gpt4 book ai didi

c# - Linq使用案例

转载 作者:行者123 更新时间:2023-11-30 21:43:25 25 4
gpt4 key购买 nike

我想在 TableType 上应用条件。

If t.TableName='limit' then TabeType should be A_TypeTable
If t.TableName='health' then TabeType should be B_TypePolicy
If t.TableName='waiting' then TabeType should be C_TypeTable

下面是查询。我不确定在哪里分配 case 语句。

 var query = from a in tableA
join b in tableB on a.Hid equals b.Hid into ab
select new
{

TableType= ab.Select(t=>t.TableName).FirstOrDefault(),
UserName = a.UserName,
Description = a.Description,
ImportedDate = a.ImportedDate

};

如有任何建议,我们将不胜感激。提前致谢

最佳答案

像这样尝试使用三元运算符将条件转换为 SQL 中的 CASE。

var query = from a in tableA
join b in tableB on a.Hid equals b.Hid into ab
let x= ab.Select(t => t.TableName).FirstOrDefault()
select new
{

TableType = x.equal("limit")? "A_TypeTable" :
x.equal("health") ? "B_TypeTable":
"C_TypeTable",
UserName = a.UserName,
Description = a.Description,
ImportedDate = a.ImportedDate

};

关于c# - Linq使用案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41734386/

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