.NET Core 中 EntityFrameworkCore的支持库主要有:
Script-migration
级联删除
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer("Data Source=10.10.10.237;Initial Catalog=DEV_RLS;User ID=DEV_User;Password=Devuser2020;"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Sheet>().HasOne<UserOrg>(s=>s.UserOrg).WithMany().OnDelete(DeleteBehavior.Restrict); }
根据数据库生成模型
Scaffold-DbContext -Force "Data Source=.;Initial Catalog=Test;User Id =sa;Password=sa;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/Test -UseDatabaseName
https://www.learnentityframeworkcore.com/configuration/fluent-api/ondelete-method
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell