gpt4 book ai didi

linq 如何从 var 获取值

转载 作者:行者123 更新时间:2023-12-04 22:34:14 25 4
gpt4 key购买 nike

如何从以下 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 的元素中获取 DecalExpireMonthDecalExpireYearDecalExpireDate 。然后你可以在这个日期前订购:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com