我正在使用Entity Framework代码优先,我有一个Course
具有导航属性的类Students
:
public virtual CollectionStudents { get; set;}
它工作正常,但是当我访问此导航属性时,将从数据库中检索所有数据:
var allStudents = course.Students; // Here it retrieves the data var activeStudents = allStudents.Where(n => n.Active); // Here it filter the data on memory var listOfActiveStudents = activeStudents.ToList(); // It already has the data on memory.
您可以想象,我需要在执行此操作时执行查询,.ToList()
因为我不想Students
从数据库中获取所有数据,只有活动数据库.
你知道我做错了什么吗?