Sql 查询到 EF Linq 表达式

发布于 2024-11-03 08:48:35 字数 678 浏览 2 评论 0原文

任何人都可以帮助这个 sql 查询将其转换为 EF Linq 表达式吗?

SELECT Aitimata.id, AST.dateCr, AST.StatusId, Aitimata.UniqueCode, Aitimata.CategoryId, Aitimata.Thema
FROM         Aitimata INNER JOIN
    (select a.* from AitimataStatus a join
    (select AitimaId, max(dateCr) AS dateCr
    from AitimataStatus
    group by AitimaId) b
     on a.AitimaId = b.AitimaId and a.dateCr = b.dateCr)as AST ON Aitimata.id = AST.AitimaId

重要的是这个子查询

select a.* from AitimataStatus a join
(select AitimaId, max(dateCr) AS dateCr
from AitimataStatus
group by AitimaId) b
on a.AitimaId = b.AitimaId and a.dateCr = b.dateCr

您需要额外的信息吗?

谢谢

Can anybody help with this sql Query to tranform it to EF Linq Expression?

SELECT Aitimata.id, AST.dateCr, AST.StatusId, Aitimata.UniqueCode, Aitimata.CategoryId, Aitimata.Thema
FROM         Aitimata INNER JOIN
    (select a.* from AitimataStatus a join
    (select AitimaId, max(dateCr) AS dateCr
    from AitimataStatus
    group by AitimaId) b
     on a.AitimaId = b.AitimaId and a.dateCr = b.dateCr)as AST ON Aitimata.id = AST.AitimaId

The important is this subquery

select a.* from AitimataStatus a join
(select AitimaId, max(dateCr) AS dateCr
from AitimataStatus
group by AitimaId) b
on a.AitimaId = b.AitimaId and a.dateCr = b.dateCr

you need extra info?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窝囊感情。 2024-11-10 08:48:35

它会是这样的:

from a in AitimataStatus 
let b = from  as in AitimataStatus group by and other stuff and then select
join b on a.** equals b.**

It'll be something like this:

from a in AitimataStatus 
let b = from  as in AitimataStatus group by and other stuff and then select
join b on a.** equals b.**
删除→记忆 2024-11-10 08:48:35

这是我的解决

Dim sub1 = From aitst In context.AitimataStatus
                Join aitst2 In (From aitst2 In context.AitimataStatus
                                     Group aitst2 By cid = aitst2.AitimaId Into g = Group
                                     Select New With {.AitimaId = cid, .dateCr = g.Max(Function(ddd) (ddd.dateCr))}
                                     )
                On aitst2.AitimaId Equals aitst.AitimaId And aitst2.dateCr Equals aitst.dateCr
                Select aitst

方案

SELECT 
[Extent1].[id] AS [id], 
[Extent1].[dateCr] AS [dateCr], 
[Extent1].[UserId] AS [UserId], 
[Extent1].[AitimaId] AS [AitimaId], 
[Extent1].[StatusId] AS [StatusId]
FROM  [dbo].[AitimataStatus] AS [Extent1]
INNER JOIN  (SELECT 
    [Extent2].[AitimaId] AS [K1], 
    MAX([Extent2].[dateCr]) AS [A1]
    FROM [dbo].[AitimataStatus] AS [Extent2]
    GROUP BY [Extent2].[AitimaId] ) AS [GroupBy1] ON (([Extent1].[AitimaId] = [GroupBy1].[K1]) OR (([Extent1].[AitimaId] IS NULL) AND ([GroupBy1].[K1] IS NULL))) AND (([Extent1].[dateCr] = [GroupBy1].[A1]) OR (([Extent1].[dateCr] IS NULL) AND ([GroupBy1].[A1] IS NULL)))

Here is my solution

Dim sub1 = From aitst In context.AitimataStatus
                Join aitst2 In (From aitst2 In context.AitimataStatus
                                     Group aitst2 By cid = aitst2.AitimaId Into g = Group
                                     Select New With {.AitimaId = cid, .dateCr = g.Max(Function(ddd) (ddd.dateCr))}
                                     )
                On aitst2.AitimaId Equals aitst.AitimaId And aitst2.dateCr Equals aitst.dateCr
                Select aitst

it produce

SELECT 
[Extent1].[id] AS [id], 
[Extent1].[dateCr] AS [dateCr], 
[Extent1].[UserId] AS [UserId], 
[Extent1].[AitimaId] AS [AitimaId], 
[Extent1].[StatusId] AS [StatusId]
FROM  [dbo].[AitimataStatus] AS [Extent1]
INNER JOIN  (SELECT 
    [Extent2].[AitimaId] AS [K1], 
    MAX([Extent2].[dateCr]) AS [A1]
    FROM [dbo].[AitimataStatus] AS [Extent2]
    GROUP BY [Extent2].[AitimaId] ) AS [GroupBy1] ON (([Extent1].[AitimaId] = [GroupBy1].[K1]) OR (([Extent1].[AitimaId] IS NULL) AND ([GroupBy1].[K1] IS NULL))) AND (([Extent1].[dateCr] = [GroupBy1].[A1]) OR (([Extent1].[dateCr] IS NULL) AND ([GroupBy1].[A1] IS NULL)))

.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文