LINQ GROUP BY和MAX() [英] LINQ GROUP BY and MAX()

查看:214
本文介绍了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)
});

但是我收到以下错误:

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



来自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:

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)}

这篇关于LINQ GROUP BY和MAX()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆