[英]LINQ to sql subquery with 2 tables
I need do in c# this sql query 我需要在C#中执行此sql查询
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? 如何使用LINQ to sql做到这一点? Thanks! 谢谢!
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);
}
just FYI other answer is missing where clause.don't forget where clause 仅供参考,其他答案缺少where子句。不要忘记where子句
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};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.