如何从以下 LINQ 查询中获取各个值? (我想获取 DecalExpireDate、DecalExpireMonth 和 DecalExpireYear 的值。)
var previousExpirationDate = (from d in db.CT_Decals
where d.TankID == decal.TankID
&& d.DecalStatus == "Approved"
select new
{
d.DecalExpireDate,
d.DecalExpireMonth,
d.DecalExpireYear
}).Max(d => d.DecalExpireDate);
最佳答案
我假设您想从具有最高(最后) DecalExpireDate
的元素中获取 DecalExpireMonth
、 DecalExpireYear
和 DecalExpireDate
。然后你可以在这个日期前订购:
var latest = (from d in db.CT_Decals
where d.TankID == decal.TankID && d.DecalStatus == "Approved"
orderby d.DecalExpireDate descending
select new
{
d.DecalExpireDate,
d.DecalExpireMonth,
d.DecalExpireYear
}).First();
var decalExpireDate = latest.DecalExpireDate;
var decalExpireMonth = latest.DecalExpireMonth;
var decalExpireYear = latest.DecalExpireYear;
关于linq 如何从 var 获取值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11369889/