gpt4 book ai didi

linq-to-sql - LINQ SELECT 中的 IF 语句

转载 作者:行者123 更新时间:2023-12-03 11:06:55 28 4
gpt4 key购买 nike

我正在尝试在“select new”中生成一个 IF 条件语句,该语句检查两个字段的值以填充一个属性。

from e in Employees
where e.EmployeeID == id
select new {
EmployeeID = e.EmployeeID,
EmployeeName = e.FirstName + " " + e.LastName,
Status = (if e.col1.HasValue then "This Value" else if e.col2.HasValue then "Other Value")
}

列可以为空,因此列类型是 DateTime?数据类型。

只有一列或另一列具有日期时间值,而不是两者都有。

我该怎么做呢???

最佳答案

Status = e.col1.HasValue ? "This Value" : (e.col2.HasValue ? "Other Value" : null)

关于linq-to-sql - LINQ SELECT 中的 IF 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1030041/

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