none
I wanted to get this done with LINQ to SQL RRS feed

  • Question

  • Hello, Please help me to get this done through LINQ to SQL, I'm new LiNQ and wanted to user this in one of my test application SELECT OU.OrgUnitId, MAX(ModifiedDateTime) AS MaxDate FROM dbo.OrgUnits OU INNER JOIN dbo.Deals D ON OU.OrgUnitId = D.OrgUnitId INNER JOIN dbo.DealsForecasts DF ON D.DealId=DF.DealId GROUP BY OU.OrgUnitId
    Tuesday, October 20, 2009 9:34 AM

Answers

  • Hi,

    You didnt specify which table contains the ModifiedDateTime column. Lets assume it is in DealsForecast table, then you may write:
    from ou in db.OrgUnits
    join d in db.Deals on ou.OrgUnitId equals d.OrgUnitId
    join df in db.DealsForecasts on d.DealsId equals df.DealId
    group new {ou,d,df} by ou.OrgUnitId into grp
    select new { OrgUnitId=grp.Key, MaxDate=grp.Max(p=>p.df.ModifiedDateTime) }
    
    Hope that helps.

    Regards,
    Syed Mehroz Alam
    My Blog | My Articles
    • Proposed as answer by KristoferAEditor Wednesday, October 21, 2009 3:54 AM
    • Marked as answer by Zhipeng Lee Monday, October 26, 2009 1:54 AM
    Tuesday, October 20, 2009 10:39 AM

All replies

  • SELECT OU.OrgUnitId, MAX(ModifiedDateTime) AS MaxDate FROM dbo.OrgUnits OU INNER JOIN dbo.Deals D ON OU.OrgUnitId = D.OrgUnitId INNER JOIN dbo.DealsForecasts DF ON D.DealId=DF.DealId GROUP BY OU.OrgUnitId
    Tuesday, October 20, 2009 9:35 AM
  • Hi,

    You didnt specify which table contains the ModifiedDateTime column. Lets assume it is in DealsForecast table, then you may write:
    from ou in db.OrgUnits
    join d in db.Deals on ou.OrgUnitId equals d.OrgUnitId
    join df in db.DealsForecasts on d.DealsId equals df.DealId
    group new {ou,d,df} by ou.OrgUnitId into grp
    select new { OrgUnitId=grp.Key, MaxDate=grp.Max(p=>p.df.ModifiedDateTime) }
    
    Hope that helps.

    Regards,
    Syed Mehroz Alam
    My Blog | My Articles
    • Proposed as answer by KristoferAEditor Wednesday, October 21, 2009 3:54 AM
    • Marked as answer by Zhipeng Lee Monday, October 26, 2009 1:54 AM
    Tuesday, October 20, 2009 10:39 AM