sharding/samples/Sample.MySql/multi/OtherDbContext.cs

26 lines
841 B
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Sharding;
using ShardingCore.Sharding.Abstractions;
namespace Sample.MySql.multi;
public class OtherDbContext:AbstractShardingDbContext,IShardingTableDbContext
{
public DbSet<MyUser> MyUsers { get; set; }
public OtherDbContext(DbContextOptions<OtherDbContext> options) : base(options)
{
}
2022-07-24 00:26:21 +08:00
public static string CurrentId;
public string CID => CurrentId;
public bool HasCID => !string.IsNullOrWhiteSpace(CID);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MyUser>()
.HasQueryFilter(o => !HasCID || o.Id == CID);
}
public IRouteTail RouteTail { get; set; }
}