public interface IDepartmentDataSource
{
IQueryable<Department> Departments { get; }
}
public class DepartmentDb : DbContext, IDepartmentDataSource
{
//Error: property cannot implement property....
public DbSet<Department> Departments { get; set; }
//should be:
//public IQueryable<Department> Departments { get; set; }
}
(使用来自 Pluralsight 的代码)
来自 MSDN:
public class DbSet<TEntity> : DbQuery<TEntity>,
IDbSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>,
IQueryable, IEnumerable
where TEntity : class
为什么我必须专门实现为 IQueryable ?