Ejemplo n.º 1
0
        public static void ConfigureProductManagement(
            this ModelBuilder builder,
            Action <ProductManagementModelBuilderConfigurationOptions> optionsAction = null)
        {
            Check.NotNull(builder, nameof(builder));

            var options = new ProductManagementModelBuilderConfigurationOptions(
                ProductManagementDbProperties.DbTablePrefix,
                ProductManagementDbProperties.DbSchema
                );

            optionsAction?.Invoke(options);

            /* Configure all entities here. Example:
             *
             * builder.Entity<Question>(b =>
             * {
             *  //Configure table & schema name
             *  b.ToTable(options.TablePrefix + "Questions", options.Schema);
             *
             *  b.ConfigureByConvention();
             *
             *  //Properties
             *  b.Property(q => q.Title).IsRequired().HasMaxLength(QuestionConsts.MaxTitleLength);
             *
             *  //Relations
             *  b.HasMany(question => question.Tags).WithOne().HasForeignKey(qt => qt.QuestionId);
             *
             *  //Indexes
             *  b.HasIndex(q => q.CreationTime);
             * });
             */
        }
        public static void ConfigureProductManagement(
            this ModelBuilder builder,
            Action <ProductManagementModelBuilderConfigurationOptions> optionsAction = null)
        {
            Check.NotNull(builder, nameof(builder));

            var options = new ProductManagementModelBuilderConfigurationOptions();

            optionsAction?.Invoke(options);

            builder.Entity <Product>(b =>
            {
                b.ToTable(options.TablePrefix + "Products", options.Schema);

                b.ConfigureConcurrencyStamp();
                b.ConfigureExtraProperties();
                b.ConfigureAudited();

                b.Property(x => x.Code).IsRequired().HasMaxLength(ProductConsts.MaxCodeLength);
                b.Property(x => x.Name).IsRequired().HasMaxLength(ProductConsts.MaxNameLength);

                b.HasIndex(q => q.Code);
                b.HasIndex(q => q.Name);
            });
        }