Fluent NHibernate Linq 复杂组件预加载
我们在带有遗留数据库的项目中使用 Fluent NHibernate LINQ。 我们的场景是,我们有一个包含客户信息和地址的表。 我们在 C# 中将客户和地址创建为单独的实体。地址再次引用邮政编码对象。
在映射时,我们将地址映射为客户的组件。现在我想在获取客户时立即加载邮政编码(由地址引用)以避免 N+1 选择。
当我尝试编写 Fetch(customer => customer.Address.ZipCode)
时,它说它太复杂了。我无法执行 Fetch(customer => customer.Address).ThenFetch(address => address.ZipCode)
因为 Address 与 Customer 存储在同一个表中。
我有什么办法可以解决这个问题吗?
We are using Fluent NHibernate LINQ in our project with legacy database.
Our scenario is that we have a table with Customer information with address.
We have created Customer and Address as separate entities in C#. Address again references zip code object.
While mapping, we have mapped Address as Component of Customer. Now I want to eager load Zip Code (which is referenced by Address) while fetching Customer so as to avoid N+1 selects.
When I try to write Fetch(customer => customer.Address.ZipCode)
it says its too complex. I cannot do Fetch(customer => customer.Address).ThenFetch(address => address.ZipCode)
since Address is stored in same table as Customer.
Is there any way I can solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,Linq 提供者似乎无法处理这种情况。因此,您要么使用条件或 QueryOver API
,要么在映射中禁用 ZipCode 的 LazyLoading
unfortunatly it seems the Linq-provider cant handle this situation. So either you use criteria or QueryOver API
Or disable LazyLoading of ZipCode in Mappings