Reload an entity and all Navigation Property Association- DbSet Entity Framework

If you don’t use lazy loading, you have the load the new Address explicitly (as you had to load it explicitly (with Include, for example), when you loaded the Person initially): context.Entry(myPerson).Reload(); // If the person refers to another Address in the DB // myPerson.Address will be null now if (myPerson.Address == null) context.Entry(myPerson).Reference(p => …

Read more

Conflicting changes to the role x of the relationship y have been detected

The problem is this one: MyEntity has an ID of 0 since it’s a new MyEntity. The Group is also new and contain a reference to MyEntity. So, MyEntity contains a list of Group which contain a reference back to MyEntity. The problem is that MyEntity.Group.MyEntity seems to be “new and not the same” as …

Read more

Entity Framework 4.1 DbContext Override SaveChanges to Audit Property Change

Very, very rough idea: foreach (var property in dbEntityEntry.Entity.GetType().GetProperties()) { DbPropertyEntry propertyEntry = dbEntityEntry.Property(property.Name); if (propertyEntry.IsModified) { Log.WriteAudit(“Entry: {0} Original :{1} New: {2}”, property.Name, propertyEntry.OriginalValue, propertyEntry.CurrentValue); } } I have no clue if this would really work in detail, but this is something I would try as a first step. Of course there could be …

Read more

Can I use Entity Framework 6 (not core) in .net core?

Update You can now use EF 6.3 with .NET Core 3.0: https://devblogs.microsoft.com/dotnet/announcing-ef-core-3-0-and-ef-6-3-general-availability/#what-s-new-in-ef-6-3 Below is an excerpt. However, EF Core has come a long way these days and it’s worth giving it another go before going back to something that’s reaching end-of-life soon. Specifically for your issue, EF Core supports mapping to spatial data types using …

Read more