gpt4 book ai didi

c# - 这如何转换为 SQL 到 LINQ?

转载 作者:行者123 更新时间:2023-11-30 16:26:07 26 4
gpt4 key购买 nike

只是想知道将以下 SQL 转换为 LINQ to SQL 的最佳(最快执行时间)方法是什么?

IF EXISTS (SELECT TOP 1 * FROM HealthIndicators WHERE LogDate = getdate())
UPDATE HealthIndicators SET Timeouts = 32
ELSE INSERT INTO HealthIndicators (Timeouts, 32)

如果这是转贴,我深表歉意,但我无法找到关于该主题的答案(我是新人,请多关照!)

最佳答案

var d = DateTime.Today; // or .Now
if (db.HealthIndicators.FirstOrDefault(h => h.LogDate == d) != null)
// or Any(h => h.LogDate == d)
{
// update
}
else
{
// insert
}

关于c# - 这如何转换为 SQL 到 LINQ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9143020/

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