如何使转换SQL内连接的查询VS实体框架 [英] How to make conversion SQL Inner joins query vs Entity Framework

查看:119
本文介绍了如何使转换SQL内连接的查询VS实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是三个表Service_Orders,Project_Services和公司。还有就是服务订单和CompanyID 3表之间的内连接。
我想下面的查询使用C#或Vb.net转换成具有的Lamda快递实体框架。

 选择前10名*从[Service_Orders]一,[Project_Services] b,[公司] C 
,其中a.so_no = b.service_order和c.companyId = b.compid


解决方案

lambda语法:

  VAR的查询= db.Service_Orders 
。加入(db.Project_Services,
A => a.so_no等于,
B = GT; b.service_order,
(A,b )=>新建{A,b})
。加入(db.Company,
X => xbcompid,
C => c.companyId,
(X, C)=>新建{XA,XB,C})
。取(10);



更可读的查询语法:

  VAR的查询=(从上a.so_no db.Project_Services一个在db.Service_Orders 
加入b等于b.service_order
将C在db.Company在b上。 compid等于c.companyId
选择新{A,b,C})取(10)。


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 Lamda 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 syntax:

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

Much more readable query syntax:

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内连接的查询VS实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆