将园子的博客系统升级到 .NET 10 后,下面的代码编译报错
Expression<Func<SetPropertyCalls<BlogPost>, SetPropertyCalls<BlogPost>>> setPropertyCalls = isPublish
? s => s.SetProperty(p => p.PostConfig, p => p.PostConfig | targetConfig)
: s => s.SetProperty(p => p.PostConfig, p => p.PostConfig & ~targetConfig);
var updatedCount = await QueryBlogPosts(blogId, postIds).ExecuteUpdateAsync(setPropertyCalls);
错误信息
The type or namespace name 'SetPropertyCalls<>' could not be found (are you missing a using directive or an assembly reference?)
这是 EF Core 10 的一个 breaking change,详见 ef-core-10.0/breaking-changes#mitigations-2
改为下面的代码解决了
var updatedCount = await QueryBlogPosts(blogId, postIds).ExecuteUpdateAsync(s =>
{
if (isPublish)
{
s.SetProperty(p => p.PostConfig, p => p.PostConfig | targetConfig);
}
else
{
s.SetProperty(p => p.PostConfig, p => p.PostConfig & ~targetConfig);
}
});