使用 Azure SQLServer 我试图只将一列转换为 json 格式。数据位于 nvarchar 字段中。使用For Json Auto将转换所有字段和所有行。我需要的只是转换一列。
通过转换为 json,我的意思是可以在 SSMS 中的一个新窗口中点击查看它的数据。
假设表 (Logs) 有 2 列:LogId和LogData。LogData是nvarchar(max)并包含 json 数据。
我需要的是查询表并有一个可点击的logData列。
我有这一行,直到我启用RelationalEventId.QueryClientEvaluationWarning.
这里我们要说的是根据最新的订单日期对结果(客户)进行排序.
.OrderByDescending(x=>x.orders.Max(y=>y.CreateDate))
Run Code Online (Sandbox Code Playgroud)
在配置上下文后,我意识到Max()没有转换为TSql.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.ConfigureWarnings(warning =>
{
warning.Throw(RelationalEventId.QueryClientEvaluationWarning);
});
}
Run Code Online (Sandbox Code Playgroud)
错误:
InvalidOperationException: Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'Max()' could not be translated and will be evaluated locally.
Run Code Online (Sandbox Code Playgroud)
我假设在本地计算max是反对具有更好的性能.有没有办法计算SQL Server上的最大值?
我知道&&会使评估短路,因此如果不需要,则不必评估RHS,但是EF呢?&和&&之间有什么区别(与|和||相同)?表现明智!