EDMX uses ICollection for 1:n relation ship like this
public partial class Customer
{
...
public virtual ICollection<User> Users { get; set; }
ICollection implements IEnumerable and not IQueryable so using property navigation on customer to filter by sites, retrieve all records from the DB server and filter them on the client side (it's an example not a real case) :
var users = myContext.Customer.Users.Where(u.Enabled).FirstOrDefault();
Linq query :
SELECT [Extent1].[IdCustomer] AS [IdCustomer],
[Extent1].[Enabled] AS [Enabled],
...
FROM [Framework].[User] AS [Extent1]
I have try to "force" EF to set users as queryable at runtime but that doesn't work :
var users = myContext.Customer.Users.AsQueryable().Where(u.Enabled).FirstOrDefault();
Two questions about this problem :
- Why AsQueryable doesn't work in this case ?
- Why does EDMX use ICollection and not a DbSet instead ?
- Is it possible to use a DbSet or a specialized collection with an implementation of IQueryable ?