在 stackoverflow 的回答中找到了解决方法,原来用 ExecuteUpdateAsync
就可以实现
await _questionRepository.QueryQuestionById(answer.QID)
.ExecuteUpdateAsync(s => s.SetProperty(q => q.AnswerCount, q => q.AnswerCount - 1));
生成的 SQL 语句
UPDATE [q]
SET [q].[AnswerCount] = [q].[AnswerCount] - 1
FROM [question_Item] AS [q]
WHERE [q].[QID] = @__qid_0