如何在LINQ中选择多个表?

时间:2012-02-14 07:48:27

标签: c# .net sql wpf linq

在SQL中我有:

 SELECT gu.*, cu.*
 FROM [gene_genunit] as gu, [cont_unitati] as cu
 WHERE gu.COD_UNIT = cu.COD_UNIT

我有一个WPF应用程序。

2 个答案:

答案 0 :(得分:6)

LINQ等价物将是

from gu in context.Gene
join cu in Context.Cont
on gu.Code_Unit equals cu.Code_Unit
select new 
{
   gu,
   cu
}

使用LinqPad生成查询并了解Linq

答案 1 :(得分:2)

ARHIEntities ARHModel = new ARHIEntities(); // ARHIEntities is the model name
var qry = from gu in ARHModel.gene_genunit
          from cu in ARHModel.cont_unitati
          where gu.COD_UNIT == cu.COD_UNIT
          select new { cu, gu };

编辑:添加了where条款