Putting this here for future reference and hopefully help someone else out. I have a BPM alert where I need to send the earliest NeedBy and ShipBy on OrderDtl on a particular OrderNum. Basically I needed the C# / LINQ equivalent of a SQL MIN(x) query like:
SELECT MIN(NeedByDate) as EarliestNBD
FROM OrderDtl
WHERE OrderNum = '12345'
So after trying some crazy with an array on the OrderDtl row sets to get both both dates at once and getting nowhere. I reset my thinking and it’s a simple one liner per date field. I converted to String as it’s sent in the email text.
Convert.ToDateTime( Db.OrderDtl.Where( r => r.Company == Session.CompanyID && r.OrderNum == OrderHed.OrderNum).Select( r => r.NeedByDate ).Min() ).ToString("MM/dd/yyyy");