Convert to linq ef code 6 - “DECLARE @__8__locals1_startDate_0 datetime2 = ‘2024-05-01T08:00:00.0000000’;
DECLARE @__8__locals1_endDate_1 datetime2 = ‘2024-05-20T15:51:11.3652608+07:00’;

SELECT [t].[Value] AS [packNumber], [t5].[Value] AS [part], [t6].[Value] AS [partDescription], N’’ AS [quantityLayers], [t8].[Value] AS [partType], [t0].[Value] AS [quantity], [t1].[Value] AS [currentQuantity], [t3].[Value] AS [units], [t9].[actionDT] AS [recivedDT], [t2].[Value] AS [Status], [t4].[Value] AS [Location], [t7].[Value] AS [fifoNumber]
FROM [EventFrame] AS [e]
LEFT JOIN (
SELECT [e0].[EventFrameId], [e0].[Value]
FROM [EventFrameAttribute] AS [e0]
WHERE [e0].[Name] = N’Номер партии/ изделия’
) AS [t] ON [e].[ObjectId] = [t].[EventFrameId]
LEFT JOIN (
SELECT [e1].[EventFrameId], [e1].[Value]
FROM [EventFrameAttribute] AS [e1]
WHERE [e1].[Name] = N’Исходное количество, основное’
) AS [t0] ON [e].[ObjectId] = [t0].[EventFrameId]
LEFT JOIN (
SELECT [e2].[EventFrameId], [e2].[Value]
FROM [EventFrameAttribute] AS [e2]
WHERE [e2].[Name] = N’Текущее количество, основное’
) AS [t1] ON [e].[ObjectId] = [t1].[EventFrameId]
LEFT JOIN (
SELECT [e3].[EventFrameId], [e3].[Value]
FROM [EventFrameAttribute] AS [e3]
WHERE [e3].[Name] = N’Статус’
) AS [t2] ON [e].[ObjectId] = [t2].[EventFrameId]
LEFT JOIN (
SELECT [e4].[EventFrameId], [e4].[Value]
FROM [EventFrameAttribute] AS [e4]
WHERE [e4].[Name] = N’ЕИ, основная’
) AS [t3] ON [e].[ObjectId] = [t3].[EventFrameId]
LEFT JOIN (
SELECT [e5].[EventFrameId], [e5].[Value]
FROM [EventFrameAttribute] AS [e5]
WHERE [e5].[Name] = N’Место хранения’
) AS [t4] ON [e].[ObjectId] = [t4].[EventFrameId]
LEFT JOIN (
SELECT [e6].[EventFrameId], [e6].[Value]
FROM [EventFrameAttribute] AS [e6]
WHERE [e6].[Name] = N’Изделие’
) AS [t5] ON [e].[ObjectId] = [t5].[EventFrameId]
LEFT JOIN (
SELECT [e7].[EventFrameId], [e7].[Value]
FROM [EventFrameAttribute] AS [e7]
WHERE [e7].[Name] = N’Наименование изделия’
) AS [t6] ON [e].[ObjectId] = [t6].[EventFrameId]
LEFT JOIN (
SELECT [e8].[EventFrameId], [e8].[Value]
FROM [EventFrameAttribute] AS [e8]
WHERE [e8].[Name] = N’Сквозной номер партии’
) AS [t7] ON [e].[ObjectId] = [t7].[EventFrameId]
LEFT JOIN (
SELECT [e9].[EventFrameId], [e9].[Value]
FROM [EventFrameAttribute] AS [e9]
WHERE [e9].[Name] = N’Тип изделия’
) AS [t8] ON [e].[ObjectId] = [t8].[EventFrameId]
inner JOIN (
SELECT [t10].[actionDT], [t10].[Value]
FROM (
SELECT [t12].[Value] AS [actionDT], [t13].[Value], ROW_NUMBER() OVER(PARTITION BY [t13].[Value] ORDER BY [e10].[ObjectId], [t11].[ObjectId], [t12].[ObjectId], [e11].[CreationDate], [e11].[TimeStamp], [e11].[EventFrameAttributId], [t13].[ObjectId]) AS [row]
FROM [EventFrame] AS [e10]
INNER JOIN (
SELECT [e12].[ObjectId], [e12].[EventFrameId], [e12].[Value]
FROM [EventFrameAttribute] AS [e12]
WHERE [e12].[Name] = N’Тип действия’
) AS [t11] ON [e10].[ObjectId] = [t11].[EventFrameId]
INNER JOIN (
SELECT [e13].[ObjectId], [e13].[EventFrameId], [e13].[LastValueId], [e13].[Value]
FROM [EventFrameAttribute] AS [e13]
WHERE [e13].[Name] = N’Дата/ время события’
) AS [t12] ON [e10].[ObjectId] = [t12].[EventFrameId]
INNER JOIN [EventFrameAttributeValue] AS [e11] ON [t12].[LastValueId] = [e11].[ObjectId]
INNER JOIN (
SELECT [e14].[ObjectId], [e14].[EventFrameId], [e14].[Value]
FROM [EventFrameAttribute] AS [e14]
WHERE [e14].[Name] = N’Номер партии/ изделия’
) AS [t13] ON [e10].[ObjectId] = [t13].[EventFrameId]
WHERE (((([e10].[Name] = N’Событие по партии’) AND ([e10].[IsDeleted] = CAST(0 AS bit))) AND ([t11].[Value] = N’Создание партии’)) AND ([e11].[ValueDateTime] >= @__8__locals1_startDate_0)) AND ([e11].[ValueDateTime] < @__8__locals1_endDate_1)
) AS [t10]
WHERE [t10].[row] <= 1
) AS [t9] ON [t].[Value] = [t9].[Value]
WHERE ([e].[Name] = N’Партия’) AND ([e].[IsDeleted] = CAST(0 AS bit))”