如果通过条件怎么办?

时间:2012-02-21 21:19:16

标签: c# linq join

我想在我的查询中执行 if 语句,但我不确定如何。我想表演:

join asoc2 in Personnels
on comp.Secondary_associate equals asoc2.Dpinitials

如果有可用的Second_Person数据。任何想法如何做到这一点?如果有更简单的方法,请告诉我。这是我的完整查询:

(from sc in Data
join comp in Companies
on sc.Company equals comp.Company
join anl in Personnels  
on sc.SalesP_initials equals anl.Dpinitials
join asoc1 in Personnels
on comp.First_associate equals asoc1.Dpinitials
join asoc2 in Personnels
on comp.Second_Person equals asoc2.Dpinitials
select new {
MyCompany = sc.Company,
ReleaseDate = sc.Release_date,  
WebHeadline = sc.Short_subject,
EmailTo =   
    anl.Last_name + ", " + anl.First_name + " <" + anl.Email_address.Trim() + ">; " 
    + 
    asoc1.Last_name + ", " + asoc1.First_name + " <" + asoc1.Email_address.Trim() + ">; " 
    +
    asoc2.Last_name + ", " + asoc2.First_name + " <" + asoc2.Email_address.Trim() + ">"
}).FirstOrDefault ()

现在,它只显示null,因为* comp.Second_Person *不存在。

1 个答案:

答案 0 :(得分:0)

您可以在linq中使用“where”来过滤数据