其中.NET ORM可以用此方案处理 [英] Which .net ORM can deal with this scenario

查看:110
本文介绍了其中.NET ORM可以用此方案处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从<一个href="http://stackoverflow.com/questions/29040/linq-to-sql-can-i-eager-load-only-one-field-in-a-joined-table">$p$pvious问题,我知道的LINQ to SQL是不能急于负载foreingKey表的某些文件。

From a previous question, I learn that Linq to SQL is not able to eager load only certain files of foreingKey tables.

所以,我问什么.NET ORM可以支持包括这种类型的实体类中声明,只有一个数据库调用,没有手动映射的结果与目标。

So I'm asking what .net ORM can support including this type of statement inside a entity class, with only one DB call and without manually mapping the result with the object.

  -- simplified for clarity
  SELECT Order.*, Product.Name, Customer.Name, OrderType.Name, Provider.Name
  FROM Order
      INNER JOIN Product on Order.ProductID = Product.ProductID
      INNER JOIN Customer on Order.CustomerID = Customer.CustomerID
      INNER JOIN OrderType on Order.OrderTypeID = OrderType.OrderTypeID
      INNER JOIN Provider on Order.ProviderID = Provider.ProviderID

我想保持尽可能简单(尽量避免NHibernate和等)

I want to keep it as simple as possible (trying to avoid NHibernate and such)

推荐答案

作为投影的一部分,LINQ到SQL应该处理的 - 你试过

As part of a projection, LINQ-to-SQL should handle that - have you tried

select new {Order = order, ProductName = order.Product.Name,
             CustomerName = order.Customer.Name,
             OrderType = order.OrderType.Name } // etc

如果想让这些属性成为对象模型本身......棘手的一部分,而不是非常的实体关系。你可以在局部类添加属性,但你必须做大量的负载选择,使他们热切地加载。在现实中,它可能是不值得给它多么复杂的对象模型。

If you want those properties to become part of the object model itself... trickier, and not very entity related. You could add properties in the partial class, but you'd have to do lots of load-options to make them load eagerly. In reality, it probably isn't worth it given how it complicated the object model.

这篇关于其中.NET ORM可以用此方案处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆