Public Overrides Function SaveChanges() As Integer
' Get all Added/Deleted/Modified entities (not Unmodified or Detached)
For Each ent As DbEntityEntry In Me.ChangeTracker.Entries().Where(Function(p) p.State = System.Data.EntityState.Added OrElse p.State = System.Data.EntityState.Deleted OrElse p.State = System.Data.EntityState.Modified)
If ent.State = EntityState.Deleted AndAlso ent.OriginalValues.PropertyNames.Contains("IsDeleted") Then
ent.State = EntityState.Modified
ent.Property("IsDeleted").CurrentValue = True
End If
If ent.State = EntityState.Added AndAlso ent.CurrentValues.PropertyNames.Contains("IsDeleted") Then
ent.Property("IsDeleted").CurrentValue = False
End If
Next
Return MyBase.SaveChanges()
End Function
When working with one-to-many relationships, i get the following error at the mybase.savechanges():
An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types.
The innerexeption is this:
{"A relationship from the 'DepartementCustomer' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Customer' must also in the 'Deleted' state."}
What am i missing?

New Topic/Question
Reply


MultiQuote




|