当我将项目的目标框架从.NET核心5更改为.NET Core 6时,下面的代码会引发异常,因此无法编译。
if (Database.IsMySql())
{
modelBuilder.MutableEntities()
.Where(entity => entity.GetProperties().Any(DatabaseHelper.HasGeneratedTimestamp))
.ForEach(entity =>
{
var properties = entity.GetProperties().Where(DatabaseHelper.HasGeneratedTimestamp);
var table = entity.GetTableName();
var key = (entity.FindPrimaryKey() ?? throw new InvalidOperationException($"primary key not defined on {table}"))
.Properties
.Select(property => property.Name)
.Apply(columns => columns.Count() > 1 ? $"({columns.Join(", ")})" : columns.First());
properties.Where(DatabaseHelper.IsOnInsert).ForEach(property =>
{
// property.SetDefaultValue(DateTimeOffset.Now);
});
properties.Where(DatabaseHelper.IsOnUpdate).ForEach(property =>
{
// // property.SetDefaultValue(DateTimeOffset.Now);
// if (property.ValueGenerated == ValueGenerated.OnAddOrUpdate)
// property.SetDefaultValueSql("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
});
});
}其中Any(DatabaseHelper.HasGeneratedTimestamp)抛出以下错误:
无法从“方法组”转换为“Func”

如何纠正此错误?有什么包需要更新吗?
发布于 2022-10-21 09:13:15
听起来它似乎在艰难地决定一个特定的方法重载--大概是Any获得了一些重载,这使得事情变得模糊不清;也许可以帮助它:
.Any(prop => DatabaseHelper.HasGeneratedTimestamp(prop))发布于 2022-10-21 12:41:57
接口IMutableProperty已在EFCore 5和EFCore 6之间更改为
public interface IMutableProperty: IMutablePropertyBase, IProperty至
public interface IMutableProperty: IMutablePropertyBase, IReadOnlyProperty因此,IMutableProperty类型不再与IProperty兼容。最简单的解决方案是将助手方法更改为
public static bool HasGeneratedTimestamp(this IProperty property)至
public static bool HasGeneratedTimestamp(this IMutableProperty property)或
public static bool HasGeneratedTimestamp(this IReadOnlyProperty property)https://stackoverflow.com/questions/74151242
复制相似问题