Hopefully the title was clear enough. My repository method looks like this :
public async Task<List<Model>> GetAllByCode(string code)
{
using (var ctx = new DatabaseContext())
{
return await ctx.Models.Where(m => m.Code.Equals(code)).ToListAsync();
}
}
Out of the result of that method, I create an observable collection which I bind to the Combobox in the view.
Models = new ObservableCollection<Model>(await ModelRepository.GetAllByCode("code"));
But the ObservableCollection is always empty. I can even see the results in Debugger (if I'm not mistaken, it's an IEnumerable
or IQueryable
collection). I'm 100% sure that database is okay, because when I use
return await ctx.Models.ToListAsync();
it returns all the rows from the database.
Can anyone tell me what I'm doing wrong?
Edit :
The problem is in entity framework. I still haven't found a solution, but my context doesn't retrieve new data from the table, instead he always takes cached (I suppose) version even though I'm using a disposable context with every request.
Still not answer to it though.