LINQ GROUP BY和MAX()

编程入门 行业动态 更新时间:2024-10-27 16:28:42
本文介绍了LINQ GROUP BY和MAX()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好,我正试图找出如何在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 =(来自this._wapDatabase.EffectiveDates中的e 将this._wapDatabase.Sites中的c加入c。c.Site_Id中的b $ b等于e.EffectiveDate_SiteId 将组e中的c.Site_Name加入r 选择新的 { r.Key.SiteName, EffectiveDate = r.Max(d => d.EffectiveDate_Date)});

但是我收到以下错误:

i.stack.imgur/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 来自WAPMaster.Factsheets.EffectiveDate中的e 在WAPMaster.Configuration.Site中加入c on c.Site_Id等于e.EffectiveDate_SiteId group e by c.Site_Name into r 选择新{SiteName = r.Key,EffectiveDate = r.Max(d => d.EffectiveDate_Date)}

Hello I'm trying to find out how to write an SQL sentence in LINQ but I can't find a way to do it for the moment, this is the SQL command:

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

Can someone help me witht he linq syntax please? Thanks

**I'm trying this so far (thanks 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) });

But I'm getting the following error:

i.stack.imgur/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)}

更多推荐

LINQ GROUP BY和MAX()

本文发布于:2023-10-20 01:05:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LINQ   GROUP   MAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!