Whenever we want to use IEnumerable extension methods instead IQueryable version, we have use AsEnumerable() method.
var list = context.Details.AsEnumerable().Where(x => x.Code == "A1").ToList();
Why DbSet used IQueryable version of methods Like(Where , Select ,...) by default when other version available?
You'd usually want to use the IQueryable
form, so that the filtering is done on the database instead of locally.
The code you've got will pull all records down to the client, and filter them there - that's extremely inefficient. You should only use AsEnumerable()
when you're trying to do something that can't be performed in the database - usually after providing a server-side filter. (You may be able to do a coarse filter on the server, then a more fine-grained filter locally - but at least then you're not pulling all the records...)
See more on this question at Stackoverflow