【问题标题】:Adding a Condition to a LINQ join向 LINQ 联接添加条件
【发布时间】:2014-08-26 14:35:37
【问题描述】:

我正在使用以下 linq 查询:

  var docList = from c in container.DocumentDeliveryPreferences 
                            join o in container.Documents on c.DocumentId equals o.DocumentId
                            select new { o.Name, o.DocumentType, c.CustomerId };

如何修改它以仅选择 c.CustomerId 等于 X(某些参数)的文档?

【问题讨论】:

  • 只需在select 之前添加where c.CustomerID == X ??
  • 这和 ASP.NET 有什么关系?

标签: c# sql asp.net linq


【解决方案1】:

您可以尝试以下方法:

 var docList = from c in container.DocumentDeliveryPreferences 
               join o in container.Documents 
               on c.DocumentId equals o.DocumentId
               where c.CustomerId == X
               select new { o.Name, o.DocumentType, c.CustomerId };

X 是您的参数。

【讨论】:

  • 谢谢,这行得通,我把 where 放错地方了。
猜你喜欢
  • 2012-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多