简体   繁体   English

哪个.net ORM可以处理这种情况

[英]Which .net ORM can deal with this scenario

From a previous question , I learn that Linq to SQL is not able to eager load only certain files of foreingKey tables. 从上一个问题 ,我了解到Linq to SQL无法仅加载foreingKey表的某些文件。

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. 所以我问.net ORM可以支持在实体类中包含这种类型的语句,只需要一次DB调用,而无需手动将结果映射到对象。

  -- 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

I want to keep it as simple as possible (trying to avoid NHibernate and such) 我想尽量保持简单(试图避免NHibernate等)

As part of a projection, LINQ-to-SQL should handle that - have you tried 作为投影的一部分,LINQ-to-SQL应该处理 - 你试过吗?

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. 实际上,鉴于它如何使对象模型复杂化,它可能是不值得的。

DataObjects.Net handles this by absolutely the same way as LINQ 2 SQL: DataObjects.Net以与LINQ 2 SQL完全相同的方式处理它:

from order in Query<Order>.All
where ...
select new {
  Order = order, 
  ProductName = order.Product.Name,
  CustomerName = order.Customer.Name,
  OrderType = order.OrderType.Name 
}

There are times that you're just going to have to 'do the work yourself' and not rely on an ORM for specific function. 有些时候你只需要“自己做”,而不是依靠ORM来完成特定的功能。 This may be one of those times. 这可能是其中之一。 You could put this information into a stored procedure, and pass in the objects as parameters. 您可以将此信息放入存储过程,并将对象作为参数传递。

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

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