如何使用LINQ to SQL编写这个?

时间:2013-03-03 05:17:18

标签: sql linq linq-to-sql

LINQ to SQL中此SQL查询的等效内容是什么?

select *
from Leads, LeadCustomAttributes LCA  
where Leads.LeadID = LCA.LeadID  
&& LCA.AttributeID in ('2','4','2')  

2 个答案:

答案 0 :(得分:1)

var query =
    from lead in db.Leads
    from lca in db.LeadCustomAttributes
    where lead.LeadID == lca.LeadID
    where new[] { "2", "4" }.Contains(lca.AttributeID)
    select new { lead, lca };

答案 1 :(得分:0)

int[] ids = { 2, 4, 2};

var result = from leads in context.Leads
             join LCA in context.LeadCustomAttributes
             ON leads.LeadID = LCA.LeadID
             Where ids.Contains(ids.ContainsLeadCustomAttributes)
             select leads;