How write this SQL in LINQ, please?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald S. Cook

    How write this SQL in LINQ, please?

    Any idea how to write this in LINQ?

    SELECT am.AnimalId,
    MAX(am.AnimalMo veActualDateTim e) AS AnimalMoveActua lDateTime
    FROM AnimalMove am
    INNER JOIN Animal a ON am.AnimalId = a.AnimalId
    INNER JOIN Lookup l ON a.StatusLookupI d = l.LookupId
    WHERE l.LookupCode = 'ONY'
    GROUP BY am.AnimalId

    Thanks for any help,
    Ron

  • Daniel Ruehle

    #2
    Re: How write this SQL in LINQ, please?

    Here you go:

    from am in dc.AnimalMove
    where am.Animal.Looku p.LookupCode == "ONY"
    group am by am.AnimalId into g
    select new
    {
    g.Key,
    AnimalMoveActua lDateTime = g.Max(g2 =g2.AnimalMoveA ctualDateTime)
    }

    Not having your mapping, I can't syntax check that, but it should be close.

    Regards,
    Dan Ruehle

    "Ronald S. Cook" <rcook@westinis .comwrote in message
    news:50A0EFA8-5DCD-41F6-8814-CBA9BB8F1F2D@mi crosoft.com...
    Any idea how to write this in LINQ?
    >
    SELECT am.AnimalId,
    MAX(am.AnimalMo veActualDateTim e) AS AnimalMoveActua lDateTime
    FROM AnimalMove am
    INNER JOIN Animal a ON am.AnimalId = a.AnimalId
    INNER JOIN Lookup l ON a.StatusLookupI d = l.LookupId
    WHERE l.LookupCode = 'ONY'
    GROUP BY am.AnimalId
    >
    Thanks for any help,
    Ron
    >

    Comment

    • Ronald S. Cook

      #3
      Re: How write this SQL in LINQ, please?

      THANKS!

      "Daniel Ruehle" <dan@reallyinc. comwrote in message
      news:F9EB877F-6F84-4A9B-9493-ACA8D7E2E19F@mi crosoft.com...
      Here you go:
      >
      from am in dc.AnimalMove
      where am.Animal.Looku p.LookupCode == "ONY"
      group am by am.AnimalId into g
      select new
      {
      g.Key,
      AnimalMoveActua lDateTime = g.Max(g2 =g2.AnimalMoveA ctualDateTime)
      }
      >
      Not having your mapping, I can't syntax check that, but it should be
      close.
      >
      Regards,
      Dan Ruehle
      >
      "Ronald S. Cook" <rcook@westinis .comwrote in message
      news:50A0EFA8-5DCD-41F6-8814-CBA9BB8F1F2D@mi crosoft.com...
      >Any idea how to write this in LINQ?
      >>
      >SELECT am.AnimalId,
      >MAX(am.AnimalM oveActualDateTi me) AS AnimalMoveActua lDateTime
      >FROM AnimalMove am
      >INNER JOIN Animal a ON am.AnimalId = a.AnimalId
      >INNER JOIN Lookup l ON a.StatusLookupI d = l.LookupId
      >WHERE l.LookupCode = 'ONY'
      >GROUP BY am.AnimalId
      >>
      >Thanks for any help,
      >Ron
      >>
      >

      Comment

      Working...