John Soer
John Soer

Reputation: 551

DBContext.Entry(Entity).Property(fieldname) stopped working after upgrading to dotnet core 2.2

I have a generic method that I call to add a detached entity to the DBContext

After the update the GetProperties does not return none nullable TimeSpan properties.

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

Upvotes: 1

Views: 71

Answers (1)

John Soer
John Soer

Reputation: 551

This is not an issue with dotnet core 2.2

The newer version of dotnet core is more strict.

In the generated class I had

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

In the generated partial class I had

[NotMapped]
TimeSpan? ISchedule.StartTime

[NotMapped]
TimeSpan? ISchedule.EndTime

In the new version the [NotMapped] attribute suppresses both StartTime properties

Upvotes: 1

Related Questions