user3235831
user3235831

Reputation: 45

LINQ to sql subquery with 2 tables

I need do in c# this sql query

select a.Codigo,c.Capacidad,c.Dia,c.jefe
from Autonomo a, Centro c
where a.Codigo_Centro=c.Codigo and a.Codigo_PC=1022;

How can I do it with LINQ to sql? Thanks!

Upvotes: 0

Views: 249

Answers (2)

ClearLogic
ClearLogic

Reputation: 3682

just FYI other answer is missing where clause.don't forget where clause

var query =  from a in Autonomo 
             join c in Centro 
             on a.Codigo_Centro equals c.Codigo
             where a.Codigo_PC == 1022
             select new { a.Codigo,c.Capacidad,c.Dia,c.jefe};

Upvotes: 1

Freud Alexandro
Freud Alexandro

Reputation: 21

Try:

var resultado =  
    from a in Autonomo 
    join c in Centro on a.Codigo_Centro equals c.Codigo 
    select new { a.Codigo,c.Capacidad,c.Dia,c.jefe}; 

To print:

foreach (var item in resultado) 
{  
    Console.WriteLine(item.Codigo + ", " + item.Capacidad);   
} 

Upvotes: 2

Related Questions