gpt4 book ai didi

c# - LINQ GROUP BY 和 MAX()

转载 作者:行者123 更新时间:2023-11-30 13:33:03 30 4
gpt4 key购买 nike

我正在尝试找出如何在 LINQ 中编写 SQL 语句,但暂时找不到方法,这是 SQL 命令:

SELECT cs.Site_Name, MAX(ed.EffectiveDate_Date)
FROM [WAPMaster].[Factsheets].[EffectiveDate] ed,
[WAPMaster].[Configuration].[Site] cs
WHERE cs.Site_Id = ed.EffectiveDate_SiteId
GROUP BY cs.Site_Name

有人可以帮我了解 linq 语法吗?

**我目前正在尝试这个(感谢 levanlevi)

var test = (from e in this._wapDatabase.EffectiveDates
join c in this._wapDatabase.Sites
on c.Site_Id equals e.EffectiveDate_SiteId
group e by c.Site_Name into r
select new
{
r.Key.SiteName,
EffectiveDate = r.Max(d => d.EffectiveDate_Date)
});

但我收到以下错误:

http://i.stack.imgur.com/AkJ5V.png

最佳答案

SELECT  cs.Site_Name ,
MAX(ed.EffectiveDate_Date)
FROM [WAPMaster].[Factsheets].[EffectiveDate] ed ,
[WAPMaster].[Configuration].[Site] cs
WHERE cs.Site_Id = ed.EffectiveDate_SiteId
GROUP BY cs.Site_Name



from e in WAPMaster.Factsheets.EffectiveDate
join c in WAPMaster.Configuration.Site
on c.Site_Id equals e.EffectiveDate_SiteId
group e by c.Site_Name into r
select new { SiteName = r.Key, EffectiveDate = r.Max(d=>d.EffectiveDate_Date)}

关于c# - LINQ GROUP BY 和 MAX(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10085947/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com