如何使转换SQL Inner连接查询与实体框架 [英] How to make conversion SQL Inner joins query vs Entity Framework
本文介绍了如何使转换SQL Inner连接查询与实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里有三个表Service_Orders,Project_Services和Company。服务订单和公司ID之间有3个表之间的内部连接。
我想要下面的查询使用C#或Vb.net将Lambda Express转换为Entity框架。
Here are three tables Service_Orders, Project_Services and Company. There is inner join between 3 tables by Service Order and CompanyID. I want below query to convert into Entity framework with Lambda Express using C# or Vb.net.
select top 10 * from [Service_Orders] a,[Project_Services] b,[Company] c
where a.so_no = b.service_order and c.companyId = b.compid
推荐答案
Lambda语法:
var query = db.Service_Orders
.Join(db.Project_Services,
a => a.so_no equals,
b => b.service_order,
(a,b) => new { a, b })
.Join(db.Company,
x => x.b.compid,
c => c.companyId,
(x,c) => new { x.a, x.b, c })
.Take(10);
更多可读查询语法:
var query = (from a in db.Service_Orders
join b in db.Project_Services on a.so_no equals b.service_order
join c in db.Company on b.compid equals c.companyId
select new { a, b, c }).Take(10);
这篇关于如何使转换SQL Inner连接查询与实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文