CodeGo.net>这如何转换为SQL到LINQ?
作者:互联网
只是想知道将以下SQL转换为LINQ到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
}
标签:linq-to-sql,linq,sql-server-2008,sql,c 来源: https://codeday.me/bug/20191201/2083350.html