How write this SQL in LINQ, please?

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

Any idea how to write this in LINQ?

SELECT am.AnimalId,
MAX(am.AnimalMoveActualDateTime) AS AnimalMoveActualDateTime
FROM AnimalMove am
INNER JOIN Animal a ON am.AnimalId = a.AnimalId
INNER JOIN Lookup l ON a.StatusLookupId = l.LookupId
WHERE l.LookupCode = 'ONY'
GROUP BY am.AnimalId

Thanks for any help,
Ron
 
Here you go:

from am in dc.AnimalMove
where am.Animal.Lookup.LookupCode == "ONY"
group am by am.AnimalId into g
select new
{
g.Key,
AnimalMoveActualDateTime = g.Max(g2 => g2.AnimalMoveActualDateTime)
}

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

Regards,
Dan Ruehle
 
THANKS!

Daniel Ruehle said:
Here you go:

from am in dc.AnimalMove
where am.Animal.Lookup.LookupCode == "ONY"
group am by am.AnimalId into g
select new
{
g.Key,
AnimalMoveActualDateTime = g.Max(g2 => g2.AnimalMoveActualDateTime)
}

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

Regards,
Dan Ruehle
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top