Ejemplo n.º 1
0
 //let EF take care of its rule that you can't insert a samurai without
 //SOME instance of SecretIdentity added (ownedEntities cannot be null)
 public override int SaveChanges()
 {
     foreach (var entry in ChangeTracker.Entries()
              .Where(e => e.Entity is Samurai && e.State == EntityState.Added))
     {
         if (entry.Entity is Samurai samurai)
         {
             if (entry.Reference("SecretIdentity").CurrentValue == null)
             {
                 entry.Reference("SecretIdentity").CurrentValue = PersonName.Empty();
             }
         }
     }
     return(base.SaveChanges());
 }