Click here to Skip to main content
15,888,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I have one query which I wrote in SQL but now i want to convert it to EF and I am finding difficulty on understanding how do I incorporate multiple select statements in EF

SQL Query:

SQL
SELECT TOP {count} * FROM (SELECT co.orderid,co.orderStatusId, co.paymenttransactionstatusid, (SELECT Count(IdProductSelect) FROM orderproductselect ops WHERE ops.orderid = co.orderid AND co.orderstatusid IN ( 2, 9 ) AND ops.quantity - ops.splitquantity > 1) AS LineItemsCount FROM ci_orders co) AS temp WHERE lineitemscount > 1 AND paymenttransactionstatusid = 1 AND orderid NOT IN (SELECT orderid FROM ordersplit) AND orderid Not IN (SELECT ChildOrderId FROM ordersplit) ORDER BY LineItemsCount


What I have tried:

Tried EF:

SQL
public static List<ci_orders> GetOrdersWithMultipleLineItemAndQTY(int count)
{
using (var context = GetDbContext())
{
var jobList = context.Orders
.OrderByDescending(x => x.orderId)
.Take(count).ToList();
return jobList;
}
}
Posted
Updated 12-Jun-20 0:46am

1 solution

I would treat each SELECT as a unique EF query and you can select from the other queries (which are IQueryable<t> after all)

Just build it up with a number of distinct queries
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900