升级到dotnet core 2.2后,DBContext.Entry(Entity).Property(fieldname)停止工作

时间:2019-08-21 08:19:37

标签: c# .net entity-framework-core

我有一个通用方法,可以将其添加到DBContext中

更新后,GetProperties不会返回任何可为空的TimeSpan属性。

public void AddEntity<T>(DbSet<T> entityList, T entity) where T : BaseEntity
{
    DBContext.Entry(entity).Metadata.GetProperties()
}

1 个答案:

答案 0 :(得分:1)

这不是dotnet core 2.2的问题

新版的dotnet core更加严格。

在生成的类中,我有

public TimeSpan StartTime { get; set; }
public TimeSpan EndTime { get; set; }

在生成的局部类中,我拥有

[NotMapped]
TimeSpan? ISchedule.StartTime

[NotMapped]
TimeSpan? ISchedule.EndTime

在新版本中,[NotMapped]属性会同时抑制两个StartTime属性