2021-11-07 11:29:37 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Sample.SqlServerShardingTable.Entities;
|
|
|
|
|
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
|
|
|
|
using ShardingCore.Sharding;
|
|
|
|
|
using ShardingCore.Sharding.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Sample.SqlServerShardingTable
|
|
|
|
|
{
|
|
|
|
|
public class MyDbContext:AbstractShardingDbContext,IShardingTableDbContext
|
|
|
|
|
{
|
|
|
|
|
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
|
modelBuilder.Entity<Order>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(o => o.Id);
|
|
|
|
|
entity.Property(o => o.Id).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o=>o.Payer).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o => o.Area).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o => o.OrderStatus).HasConversion<int>();
|
|
|
|
|
entity.ToTable(nameof(Order));
|
|
|
|
|
});
|
|
|
|
|
modelBuilder.Entity<SysUser>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(o => o.Id);
|
|
|
|
|
entity.Property(o => o.Id).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o=>o.Name).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o=>o.Area).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o => o.SettingCode).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.ToTable(nameof(SysUser));
|
|
|
|
|
});
|
|
|
|
|
modelBuilder.Entity<Setting>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(o => o.Code);
|
|
|
|
|
entity.Property(o => o.Code).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.Property(o=>o.Name).IsRequired().IsUnicode(false).HasMaxLength(50);
|
|
|
|
|
entity.ToTable(nameof(Setting));
|
|
|
|
|
});
|
2021-12-24 15:23:55 +08:00
|
|
|
|
modelBuilder.Entity<MultiShardingOrder>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(o => o.Id);
|
|
|
|
|
entity.Property(o => o.Id).ValueGeneratedNever();
|
|
|
|
|
entity.Property(o=>o.Name).IsRequired().IsUnicode(false).HasMaxLength(50);
|
2021-12-28 09:46:33 +08:00
|
|
|
|
entity.HasQueryFilter(o => o.IsDelete == false);
|
2021-12-29 23:22:24 +08:00
|
|
|
|
entity.HasQueryFilter(o => o.Name == "123");
|
2021-12-24 15:23:55 +08:00
|
|
|
|
entity.ToTable(nameof(MultiShardingOrder));
|
|
|
|
|
});
|
2021-11-07 11:29:37 +08:00
|
|
|
|
}
|
2021-12-17 08:42:21 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// empty impl
|
|
|
|
|
/// </summary>
|
2021-11-07 11:29:37 +08:00
|
|
|
|
public IRouteTail RouteTail { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|