gpt4 book ai didi

linq-to-sql - 如何在 LINQ-to-SQL where 条件中处理可为空的 DateTime?

转载 作者:行者123 更新时间:2023-12-01 23:09:00 25 4
gpt4 key购买 nike

我需要选择尚未过期的优惠券列表。那就是:

where Coupon.ExpiresOn > DateTimeUtc.Now

问题是 Coupon.ExpiresOn 是 DateTime (DateTime?) 的可空值。上面的代码不会在 Coupon.ExpiresOn 中返回具有空值的优惠券。如何更改它以返回空值?感谢您的帮助。

最佳答案

在你的位置允许空值,像这样:

where Coupon.ExpiresOn == null || Coupon.ExpiresOn > DateTimeUtc.Now

关于linq-to-sql - 如何在 LINQ-to-SQL where 条件中处理可为空的 DateTime?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4478562/

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