C# 如何将此SQL查询转换为LINQ to Entities查询?
我需要帮助在我的C代码中将SQL查询转换为实体查询。 该查询将4个不同的表组合在一起,如下所示:C# 如何将此SQL查询转换为LINQ to Entities查询?,c#,sql-server,entity-framework,tsql,linq-to-entities,C#,Sql Server,Entity Framework,Tsql,Linq To Entities,我需要帮助在我的C代码中将SQL查询转换为实体查询。 该查询将4个不同的表组合在一起,如下所示: SELECT a.email, a.status, a.createdat, b.unitprice, c.name, d.name, e.name FROM Orders a, Orderdetails b, ServiceOptions c, services d,
SELECT a.email,
a.status,
a.createdat,
b.unitprice,
c.name,
d.name,
e.name
FROM Orders a,
Orderdetails b,
ServiceOptions c,
services d,
merchants e
WHERE a.id=b.orderid AND c.id=b.serviceoptionid
AND c.serviceid=d.id AND d.merchantid=e.id
我想你正在往相反的方向走。首先创建实体框架,然后使用EF中的LINQ创建SQL。它应该是EF->LINQ-SQL。EF的整个理念是用户不必创建sql。在项目中创建EF后,可以在LINQ to SQL中执行此查询。我认为您正在朝相反的方向前进。首先创建实体框架,然后使用EF中的LINQ创建SQL。它应该是EF->LINQ-SQL。EF的整个理念是用户不必创建sql。在项目中创建EF后,可以在LINQ to SQL中执行此查询
var query = from a in context.Orders
join b in context.OrderDetails on a.id equals b.orderid
join c in context.ServiceOptions on b.serviceoptionid equals c.id
join d in context.services on c.serviceid equals d.id
join e in context.merchants on d.merchantid equals e.id
select new { a.email,
a.status,
a.createdat,
b.unitprice,
c.name,
d.name,
e.name };