protected override void OnModelCreating(ModelBuilder builder) { // Needed for Identity models configuration base.OnModelCreating(builder); ConfigureUserIdentityRelations(builder); EntityIndexesConfiguration.Configure(builder); var entityTypes = builder.Model.GetEntityTypes().ToList(); // Set global query filter for not deleted entities only var deletableEntityTypes = entityTypes .Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType)); foreach (var deletableEntityType in deletableEntityTypes) { var method = SetIsDeletedQueryFilterMethod.MakeGenericMethod(deletableEntityType.ClrType); method.Invoke(null, new object[] { builder }); } // Disable cascade delete var foreignKeys = entityTypes .SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade)); foreach (var foreignKey in foreignKeys) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } }
protected override void OnModelCreating(ModelBuilder builder) { // Needed for Identity models configuration base.OnModelCreating(builder); EntityIndexesConfiguration.Configure(builder); // Disable cascade delete var foreignKeys = builder.Model .GetEntityTypes() .SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade)); foreach (var foreignKey in foreignKeys) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } }
protected override void OnModelCreating(ModelBuilder builder) { // Needed for Identity models configuration base.OnModelCreating(builder); ConfigureUserIdentityRelations(builder); EntityIndexesConfiguration.Configure(builder); var entityTypes = builder.Model.GetEntityTypes().ToList(); // Set global query filter for not deleted entities only var deletableEntityTypes = entityTypes .Where(et => et.ClrType != null && typeof(IDeletableEntity).IsAssignableFrom(et.ClrType)); foreach (var deletableEntityType in deletableEntityTypes) { var method = SetIsDeletedQueryFilterMethod.MakeGenericMethod(deletableEntityType.ClrType); method.Invoke(null, new object[] { builder }); } // Disable cascade delete var foreignKeys = entityTypes .SelectMany(e => e.GetForeignKeys().Where(f => f.DeleteBehavior == DeleteBehavior.Cascade)); foreach (var foreignKey in foreignKeys) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } builder.Entity <Vicove>().ToTable("Vicoves"); builder .Entity <VicLike>() .HasOne(vl => vl.Vic) .WithMany(v => v.VicLikes) .HasForeignKey(vl => vl.VicId); builder .Entity <Vicove>() .HasOne(a => a.Account) .WithMany(v => v.Vicove) .HasForeignKey(a => a.AccountID); builder .Entity <Badges>() .HasOne(a => a.Account) .WithMany(b => b.Badges) .HasForeignKey(a => a.AccountId); builder .Entity <FavouriteVicove>() .HasOne(a => a.Account) .WithMany(v => v.FavouriteVicove) .HasForeignKey(a => a.AccountID); builder.Entity <Account>() .Property(x => x.AllPoints) .HasDefaultValue(0); builder.Entity <Account>() .Property(x => x.UploadedVicove) .HasDefaultValue(0); }