protected override void OnModelCreating(ModelBuilder modelBuilder) { try { var compilationLibrary = DependencyContext.Default.CompileLibraries.Where(x => !x.Serviceable && x.Type == "project" && x.Type != "package"); foreach (var item in compilationLibrary) { AssemblyLoadContext.Default.LoadFromAssemblyName(new System.Reflection.AssemblyName(item.Name)) .GetTypes().Where(x => !x.IsAbstract && x.BaseType != null && x.IsAssignableTo(typeof(BaseEntity))) .ToList() .ForEach(x => { modelBuilder.Entity(x); }); } } catch (Exception e) { throw new InvalidOperationException(e.Message); } base.OnModelCreating(modelBuilder); }
标签:Core,映射,EF,modelBuilder,&&,var,new,Type From: https://www.cnblogs.com/hljjway/p/17092696.html