Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq to sql 急切地在Linq2Sql中加载实体_Linq To Sql_Eager Loading - Fatal编程技术网

Linq to sql 急切地在Linq2Sql中加载实体

Linq to sql 急切地在Linq2Sql中加载实体,linq-to-sql,eager-loading,Linq To Sql,Eager Loading,我正在尝试使用LoadWith和AssociateWith DataLoadOptions加载一个实体及其相关属性(基本的一对多)。但是,在查看生成的SQL之后,我注意到LoadWith生成的语句都是外部联接 因此,下面的代码生成所有左外部联接以获取相关属性的数据。为什么呢?有没有办法让LoadWith生成内部连接呢。我知道我可以用一个简单的“Linq连接”来实现这一点,但是,我喜欢LoadWith语法的简洁和简单。提前谢谢 存在英文产品翻译的所有客户订单 dataLoadOptions.As

我正在尝试使用LoadWith和AssociateWith DataLoadOptions加载一个实体及其相关属性(基本的一对多)。但是,在查看生成的SQL之后,我注意到LoadWith生成的语句都是外部联接

因此,下面的代码生成所有左外部联接以获取相关属性的数据。为什么呢?有没有办法让LoadWith生成内部连接呢。我知道我可以用一个简单的“Linq连接”来实现这一点,但是,我喜欢LoadWith语法的简洁和简单。提前谢谢

存在英文产品翻译的所有客户订单

dataLoadOptions.AssociateWith(c=>c.Orders
.其中(o=>o.产品
.SelectMany(p=>p.ProductTranslations)
.Any(pt=>pt.Language==“En”)
)
);

为什么需要内部联接。LINQtoSQL生成外部联接似乎很合理,因为使用内部联接时,不会获取没有订单的客户。也许你应该解释一下你想要实现什么。是的,对不起,我应该说得更清楚。我想要的是带回所有客户的订单,其中有英文产品翻译。至于外部联接,我认为Linq应该允许我显式地构造外部联接或内部联接。抱歉,如果这仍然不清楚。
dataLoadOptions.LoadWith(Of TCustomer)(Function(c) c.Orders)
dataLoadOptions.LoadWith(Of TOrder)(Function(o) o.Products)
dataLoadOptions.LoadWith(Of TProduct)(Function(p) p.ProductTranslations)
dataLoadOptions.AssociateWith(Of TProduct)(Function(c) c.ProductTranslations.Where(Function(t) t.Language = "En"))
dataLoadOptions.AssociateWith<TCustomer>(c => c.Orders
  .Where(o => o.Products
      .SelectMany(p => p.ProductTranslations)
      .Any(pt => pt.Language == "En")
  )
);