【问题标题】:How to write this using LINQ to SQL? [closed]如何使用 LINQ to SQL 编写此代码? [关闭]
【发布时间】:2013-03-03 05:17:18
【问题描述】:

在 LINQ to SQL 中这个 SQL 查询的等价物是什么?

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

【问题讨论】:

    标签: sql linq linq-to-sql


    【解决方案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 };
    

    【讨论】:

      【解决方案2】:
      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;
      

      【讨论】:

      • 谢谢你们! - 欣赏它
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 2014-02-05
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      相关资源
      最近更新 更多