convert to ef core - 'SELECT wo.[ObjectId],
wo.[Line],
wo.[StartFactDT],
wo.[Material],
wo.[MaterialDescription],
wo.[WorkOrderNumber],
wo.[Customer],
comp.Parts,
wop.Material as OperationPart,
wop.Line as OperationLine,
wop.OperationType
FROM [I-DS-PC-EML-DATA].[dbo].[u_v_RunningWorkOrders] wo
join WorkOrderOperations wop on wo.WorkOrderNumber = wop.WorkOrderNumber
join (
select woc.WorkOrderNumber, woc.OperationNumber, STRING_AGG(woc.Material,',') as Parts
from WorkOrderComponents woc
where woc.IsDeleted = 0
group by woc.WorkOrderNumber, woc.OperationNumber
) as comp on comp.WorkOrderNumber = wop.WorkOrderNumber and comp.OperationNumber = wop.OperationNumber
where wop.Status = 'Запущен' and wop.IsDeleted = 0
'
Assistant
To convert the provided SQL query to Entity Framework Core (EF Core), you can make use of Linq queries. Here’s a way to represent the SQL query using EF Core:
Assuming you have the following entities defined (you might need to adjust based on your actual entity definitions):
csharp
public class RunningWorkOrder
{
public int ObjectId { get; set; }
public int Line { get; set; }
public DateTime StartFactDT { get; set; }
public string Material { get; set; }
public string MaterialDescription { get; set; }
public string WorkOrderNumber { get; set; }
public string Customer { get; set; }
}
public class WorkOrderOperation
{
public string WorkOrderNumber { get; set; }
public string Material { get; set; }
public int Line { get; set; }
public string OperationType { get; set; }
public string Status { get; set; }
public bool IsDeleted { get; set; }
}
public class WorkOrderComponent
{
public string WorkOrderNumber { get; set; }
public int OperationNumber { get; set; }
public string Material { get; set; }
public bool IsDeleted { get; set; }
}
Then, the Linq equivalent of your SQL query might look like this:
csharp
using (var context = new YourDbContext())
{
var query = from wo in context.RunningWorkOrders
join wop in context.WorkOrderOperations
on wo.WorkOrderNumber equals wop.WorkOrderNumber
join comp in (
from woc in context.WorkOrderComponents
where !woc.IsDeleted
group woc by new { woc.WorkOrderNumber, woc.OperationNumber } into g
select new
{
g.Key.WorkOrderNumber,
g.Key.OperationNumber,
Parts = string.Join(",", g.Select(x => x.Material))
}) on new { wop.WorkOrderNumber, wop.OperationNumber } equals new { comp.WorkOrderNumber, comp.OperationNumber }
where wop.Status == "Запущен" && !wop.IsDeleted
select new
{
wo.ObjectId,
wo.Line,
wo.StartFactDT,
wo.Material,
wo.MaterialDescription,
wo.WorkOrderNumber,
wo.Customer,
comp.Parts,
OperationPart = wop.Material,
OperationLine = wop.Line,
wop.OperationType
};
var result = query.ToList();
}
Explanation:
from wo in context.RunningWorkOrders: This selects data from the RunningWorkOrders table.
join wop in context.WorkOrderOperations...: This joins the WorkOrderOperations table based on the WorkOrderNumber.
The subquery creates a grouping of components and aggregates them using string.Join to simulate STRING_AGG from SQL.
The where clause filters based on Status and IsDeleted.
Note:
Ensure that your actual entity and property names match the C# code.
Make sure to adjust the context (YourDbContext) to reflect your actual DbContext class.
Depending on the configurations (like lazy loading or eager loading), you might need to adjust how you retrieve your data, but this should give you a good starting point.