C# LINQ加入多个AND条件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19722555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 15:43:43  来源:igfitidea点击:

LINQ Join with multiple AND conditions

c#asp.net-mvclinqentity-frameworklinq-to-sql

提问by Rahul_RJ

I want to join two entities in my MVC application for data Processing through the LINQ join.

我想通过 LINQ join 在我的 MVC 应用程序中加入两个实体以进行数据处理。

For that I am trying to write the query like,

为此,我正在尝试编写这样的查询,

from enumeration in db.Enumerations
join cust in db.Customers on ( enumeration.Value equals cust.lkpStatus &&       
enumeration.EnumerationTypeID.Contains('Cust')

But I am getting Problem with this Query, So please give me some suggestion on this.

但是我遇到了这个查询的问题,所以请给我一些建议。

采纳答案by alexmac

Try this solution:

试试这个解决方案:

from enumeration in db.Enumerations.Where(e => 
                                          e.EnumerationTypeID.Contains('Cust'))
join cust in db.Customers on enumeration.Value equals cust.lkpStatus
select enumeration;

回答by praga2050

This one?

这个?

var data =     from c in db.Enumerations
               from d in db.Customers
               where c.Value.Equals(d.lkpStatus)
               && c.EnumerationTypeID.Contains('Cust')
               select c;

回答by IDeveloper

Join should be made like this:

加入应该是这样的:

var joinQuery =
from t1 in Table1
join t2 in Table2
  on new { t1.Column1, t1.Column2 } equals new { t2.Column1, t2.Column2 }
...

回答by user10921782

This works

这有效

var data = from c in db.Enumerations from d in db.Customers where c.Value==d.lkpStatus && c.EnumerationTypeID.Contains('Cust') select c;