protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.InitializeEntities();
            foreach (var entityType in GetBaseEntityTypes(builder))
            {
                GlobalTenantQueryMethodInfo.MakeGenericMethod(entityType)
                .Invoke(this, new object[] { builder });
            }

            base.OnModelCreating(builder);
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <Order>().HasKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Order>().HasIndex(p => p.TenantCode);
            builder.Entity <Order>().HasIndex(p => new { p.TenantCode, p.OrderCode }).IsUnique(true);

            builder.Entity <Recycle>().HasKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Recycle>().HasIndex(p => p.TenantCode);

            foreach (var entityType in GetBaseEntityTypes(builder))
            {
                GlobalTenantQueryMethodInfo.MakeGenericMethod(entityType)
                .Invoke(this, new object[] { builder });
            }

            base.OnModelCreating(builder);
        }
示例#3
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <Category>().HasKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Category>().HasIndex(p => p.TenantCode);
            builder.Entity <Category>().HasIndex(p => new { p.TenantCode, p.CategoryCode }).IsUnique(true);
            Guid cateID = Guid.NewGuid();

            builder.Entity <Category>().HasData(
                new Category()
            {
                TenantCode   = "SYSTEM",
                ID           = cateID,
                CategoryCode = "cate1",
                CategoryName = "商品类别1"
            });

            builder.Entity <Product>().HasKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Product>().HasIndex(p => p.TenantCode);
            builder.Entity <Product>().HasIndex(p => new { p.TenantCode, p.ProductCode }).IsUnique(true);
            builder.Entity <Product>().HasOne <Category>(p => p.Category).WithMany(p => p.Products)
            .HasForeignKey(s => new { s.TenantCode, s.CategoryId }).HasPrincipalKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Product>().Property(d => d.ProductProfile).HasColumnType("json");
            builder.Entity <Product>().HasData(
                new Product()
            {
                TenantCode    = "SYSTEM",
                ID            = Guid.NewGuid(),
                ProductCode   = "product1",
                ProductName   = "商品1",
                ProductAmount = 100,
                ProductPrice  = 60,
                CategoryId    = cateID
            });

            builder.Entity <Recycle>().HasKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Recycle>().HasIndex(p => p.TenantCode);

            foreach (var entityType in GetBaseEntityTypes(builder))
            {
                GlobalTenantQueryMethodInfo.MakeGenericMethod(entityType)
                .Invoke(this, new object[] { builder });
            }

            base.OnModelCreating(builder);
        }
示例#4
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            builder.Entity <Category>().HasIndex(p => new { p.TenantCode, p.CategoryCode }).IsUnique(true);

            builder.Entity <Product>().HasIndex(p => new { p.TenantCode, p.ProductCode }).IsUnique(true);
            builder.Entity <Product>().HasOne <Category>(p => p.Category).WithMany(p => p.Products)
            .HasForeignKey(s => new { s.TenantCode, s.CategoryId }).HasPrincipalKey(p => new { p.TenantCode, p.ID });
            builder.Entity <Product>().Property(d => d.ProductProfile).HasColumnType("json");

            foreach (var entityType in GetBaseEntityTypes(builder))
            {
                builder.Entity <Product>().HasKey(p => new { p.TenantCode, p.ID });
                builder.Entity <Product>().HasIndex(p => p.TenantCode);

                GlobalTenantQueryMethodInfo.MakeGenericMethod(entityType)
                .Invoke(this, new object[] { builder });
            }

            base.OnModelCreating(builder);
        }