public static void ConfigureBookManagement( this ModelBuilder builder, Action <BookManagementModelBuilderConfigurationOptions> optionsAction = null) { Check.NotNull(builder, nameof(builder)); var options = new BookManagementModelBuilderConfigurationOptions(); optionsAction?.Invoke(options); builder.Entity <Book>(b => { b.ToTable(BookManagementConsts.DefaultDbTablePrefix + "Books", BookManagementConsts.DefaultDbSchema); b.ConfigureByConvention(); //auto configure for the base class props b.Property(x => x.Name).IsRequired().HasMaxLength(128); b.HasOne <Author>().WithMany().HasForeignKey(x => x.AuthorId).IsRequired(); }); builder.Entity <Author>(b => { b.ToTable(BookManagementConsts.DefaultDbTablePrefix + "Authors", BookManagementConsts.DefaultDbSchema); b.ConfigureByConvention(); b.Property(x => x.Name) .IsRequired() .HasMaxLength(AuthorConsts.MaxNameLength); b.HasIndex(x => x.Name); }); }
public static void ConfigureBookManagement( this ModelBuilder builder, Action <BookManagementModelBuilderConfigurationOptions> optionsAction = null) { Check.NotNull(builder, nameof(builder)); var options = new BookManagementModelBuilderConfigurationOptions(); optionsAction?.Invoke(options); builder.Entity <Book>(b => { b.ToTable(BookManagementConsts.DefaultDbTablePrefix + "Books", BookManagementConsts.DefaultDbSchema); b.ConfigureByConvention(); //auto configure for the base class props b.Property(x => x.Name).IsRequired().HasMaxLength(128); }); builder.Entity <Customer>(b => { b.ToTable(options.TablePrefix + "Customers", options.Schema); b.ConfigureByConvention(); /* Configure more properties here */ }); }