Reputation: 487
How would I write this sql as a C# Linq to Sql statement?
DECLARE @RET DATETIME
SET @RET = (SELECT MAX(EffectiveDate)
FROM Material_Price
WHERE Material_ID = @MatID
AND EffectiveDate <= GetDate())
(It just isn't coming to me tonight)
Upvotes: 0
Views: 36
Reputation: 117064
I would tend to do something like this:
var time = db
.Material_Price
.Where(m => m.Material_ID == MatID)
.Where(m => m.EffectiveDate <= DateTime.Today)
.OrderByDescending(m => m.EffectiveDate)
.First();
Upvotes: 0
Reputation: 101681
var time = db.Material_Price.Where(m => m.Material_ID == MatID
&& m.EffectiveDate <= DateTime.Today)
.Max(m => m.EffectiveDate);
Upvotes: 1