Equivalent linq RRS feed

  • Question

  • Hi,

    i nedd equivalent linq

    SELECT        ISNULL(MAX(HistoryId), 2) AS Expr1
    FROM            ModelPricesHistory

    • Moved by Bob Beauchemin Tuesday, December 6, 2011 8:01 PM Moving to a more relevent forum (From:.NET Framework inside SQL Server)
    Tuesday, December 6, 2011 4:26 PM


  • Hi Shak;

    The following query should give the results you want.

    // Assuming ctx is the instance of the ObjectContext

    int result = (from h in ModelPricesHistory
                  group h by "MaxID" into hGroup
                  let max = hGroup.Max(hh => hh.HistoryId)
                  select max != null ? max : 2).First();

    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Marked as answer by Alan_chen Friday, December 16, 2011 1:21 AM
    Tuesday, December 6, 2011 10:16 PM