本文介绍了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_NameCan 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()
发布评论