Misi
Misi

Reputation: 748

How do I select multiple tables in LINQ?

In SQL I have :

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

I have a WPF application.

Upvotes: 2

Views: 15076

Answers (2)

Misi
Misi

Reputation: 748

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 };

EDIT: added a where clause

Upvotes: 2

Muhammad Hasan Khan
Muhammad Hasan Khan

Reputation: 35126

the LINQ equivalent would be

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

Use LinqPad to generate queries and to learn Linq

Upvotes: 6

Related Questions