2

我试图在加入 Linq to Entities 之前过滤我的数据集,但我找不到这样做的方法。我当前的 linq 查询是使左连接是:

from m in Products
          join f in FileFolders on m.ProductCode equals f.Name into list1
          from l1 in list1.DefaultIfEmpty()
          join p in Files on l1.FileFolderID equals p.FileFolderID into list2
          // I want something like p.Name == "Test" here
          from l2 in list2.DefaultIfEmpty()                                                     
          join b in BaseReferenceFile on l2.BaseReferenceFileID equals b.BaseReferenceFileID into list3
          from l3 in list3.DefaultIfEmpty()
          select new
          {
              //select some stuff here                           
          };

我想过滤文件集合,以便只有名称为“Test”的文件与 l1 连接。

我试过用 l2 过滤,l2.Name == "Test"但它不起作用。它生成一个带有内连接和左连接的奇怪查询。

我怎样才能做到这一点?

4

2 回答 2

3
join p in Files.Where(m => m.Name == "Test") on l1.FileFolderID equals p.FileFolderID into list2
于 2013-01-24T13:05:10.910 回答
1

我认为这会起作用,但这每次都会查询(对于每条记录):

   join p in (from f in Files where f.Name == "Test") on l1.FileFolderID equals p.FileFolderID into list2

最好在 select 之前使用where 。

          ...from l3 in list3.DefaultIfEmpty()
          where (l1 !=null ? l1.Name == "Test" : true)
          select new
          {
              //select some stuff here                           
          };
于 2013-01-25T05:44:58.613 回答