gpt4 book ai didi

c# - DbQuery.Include() 方法 : Is there a strong-typed variant?

转载 作者:太空狗 更新时间:2023-10-29 17:44:43 25 4
gpt4 key购买 nike

这是 EF6。我可以在我的查询中包含 .Include() 方法(没有双关语),以便从相关表中预先加载信息。但是看起来 .Include() 方法只接受一个字符串参数。有没有办法以强类型的方式做到这一点?因此,例如,我可以编写类似 MyDB.catalog_item.Include(i => i.picture) 的内容,而不是编写 MyContext.catalog_item.Include("picture")获得智能感知等优势。

最佳答案

是的,System.Data.Entity 中有一个强类型变体

用法是

.Include(i => i.Property)

引用页面还提供了有关如何在集合中包含集合和属性的示例。

例子:

query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference)).

关于c# - DbQuery.Include() 方法 : Is there a strong-typed variant?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23136299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com