This commit is contained in:
parent
b9e9713410
commit
56d3462a1d
|
@ -15,6 +15,7 @@ namespace Samples.AutoByDate.SqlServer.DbContexts
|
|||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ApplyConfiguration(new SysUserLogByDayMap());
|
||||
modelBuilder.ApplyConfiguration(new TestLogByWeekMap());
|
||||
}
|
||||
|
||||
public override Type ShardingDbContextType => this.GetType();
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace Samples.AutoByDate.SqlServer.DbContexts
|
|||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
modelBuilder.ApplyConfiguration(new SysUserLogByDayMap());
|
||||
modelBuilder.ApplyConfiguration(new TestLogByWeekMap());
|
||||
}
|
||||
|
||||
public IRouteTail RouteTail { get; set; }
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ShardingCore.Core;
|
||||
|
||||
namespace Samples.AutoByDate.SqlServer.Domain.Entities
|
||||
{
|
||||
public class TestLogByWeek:IShardingTable
|
||||
{
|
||||
public string Id { get; set; }
|
||||
[ShardingTableKey]
|
||||
public DateTime CreateDate { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Samples.AutoByDate.SqlServer.Domain.Entities;
|
||||
|
||||
namespace Samples.AutoByDate.SqlServer.Domain.Maps
|
||||
{
|
||||
public class TestLogByWeekMap:IEntityTypeConfiguration<TestLogByWeek>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<TestLogByWeek> builder)
|
||||
{
|
||||
builder.HasKey(o => o.Id);
|
||||
builder.Property(o => o.Id).IsRequired().HasMaxLength(128);
|
||||
builder.ToTable((nameof(TestLogByWeek)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Samples.AutoByDate.SqlServer.Domain.Entities;
|
||||
using Samples.AutoByDate.SqlServer.Domain.Maps;
|
||||
using ShardingCore.VirtualRoutes.Weeks;
|
||||
|
||||
namespace Samples.AutoByDate.SqlServer.Shardings
|
||||
{
|
||||
public class TestLogWeekVirtualRoute:AbstractSimpleShardingWeekKeyDateTimeVirtualTableRoute<TestLogByWeek>
|
||||
{
|
||||
public override DateTime GetBeginTime()
|
||||
{
|
||||
return new DateTime(2021, 8, 1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ namespace Samples.AutoByDate.SqlServer
|
|||
op.UseShardingOptionsBuilder((connection, builder) => builder.UseSqlServer(connection),
|
||||
(conStr,builder) => builder.UseSqlServer(conStr));
|
||||
op.AddShardingTableRoute<SysUserLogByDayVirtualTableRoute>();
|
||||
op.AddShardingTableRoute<TestLogWeekVirtualRoute>();
|
||||
});
|
||||
services.AddChronusJob();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue