简体   繁体   English

如何创建返回IQueryable的导航属性 <T> 在实体框架中

[英]How to create a Navigation Property that returns IQueryable<T> in Entity Framework

My project uses Entity Framework 6 with Repository & UnitOfWork patterns to communicate with a MSSQL database. 我的项目使用带有Repository和UnitOfWork模式的Entity Framework 6与MSSQL数据库进行通信。 all configurations are done with Code First. 所有配置均通过Code First完成。

All of the navigation properties of the Entity Objects are defined for lazy loading as such: 实体对象的所有导航属性都是为延迟加载定义的,如下所示:

public virtual ICollection<> Items  { get; set; }

this works well, and the performance is pretty good in most cases. 这样效果很好,并且在大多数情况下,性能都不错。 in some cases, however, where the navigation properties refer to a large sets of data, loading them to memory takes a while, at which point LINQing seem like a bad practice. 但是,在某些情况下,如果导航属性引用了大量数据,则将它们加载到内存需要一些时间,此时LINQing似乎是一种不好的做法。 to improve performance, it would make sense to convert some of them to IQueryable<> but EF doesn't seem to accept that kind of configuration. 为了提高性能,将其中一些转换为IQueryable <>是有意义的,但是EF似乎并不接受这种配置。

So although i could workaround this by "Querying" the repositories, in some cases i already have an entity object in memory and it feels right to be able to query its navigation properties without loading all of them, to get the data that i need via LINQ. 因此,尽管我可以通过“查询”存储库来解决此问题,但在某些情况下,我在内存中已经有一个实体对象,并且能够在不加载所有导航属性的情况下查询其导航属性,以获取我需要的数据是正确的LINQ。

Is there a way to make this work? 有没有办法使这项工作?

You do not. 你不。 This functionality is not available in Entity Framework. 该功能在实体框架中不可用。 YOu can make a feature request. 您可以提出功能请求。 But right now - no way. 但是现在-没办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM