diff --git a/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultShardingDbContext.cs b/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultShardingDbContext.cs index 91ba38af..f34e8907 100644 --- a/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultShardingDbContext.cs +++ b/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultShardingDbContext.cs @@ -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(); diff --git a/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultTableDbContext.cs b/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultTableDbContext.cs index 0058c8ab..a8fd4906 100644 --- a/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultTableDbContext.cs +++ b/samples/Samples.AutoByDate.SqlServer/DbContexts/DefaultTableDbContext.cs @@ -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; } diff --git a/samples/Samples.AutoByDate.SqlServer/Domain/Entities/TestLogByWeek.cs b/samples/Samples.AutoByDate.SqlServer/Domain/Entities/TestLogByWeek.cs new file mode 100644 index 00000000..d5b78c00 --- /dev/null +++ b/samples/Samples.AutoByDate.SqlServer/Domain/Entities/TestLogByWeek.cs @@ -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; } + } +} diff --git a/samples/Samples.AutoByDate.SqlServer/Domain/Maps/TestLogByWeekMap.cs b/samples/Samples.AutoByDate.SqlServer/Domain/Maps/TestLogByWeekMap.cs new file mode 100644 index 00000000..48c564c0 --- /dev/null +++ b/samples/Samples.AutoByDate.SqlServer/Domain/Maps/TestLogByWeekMap.cs @@ -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 + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(o => o.Id); + builder.Property(o => o.Id).IsRequired().HasMaxLength(128); + builder.ToTable((nameof(TestLogByWeek))); + } + } +} diff --git a/samples/Samples.AutoByDate.SqlServer/Shardings/TestLogWeekVirtualRoute.cs b/samples/Samples.AutoByDate.SqlServer/Shardings/TestLogWeekVirtualRoute.cs new file mode 100644 index 00000000..6e16f0d0 --- /dev/null +++ b/samples/Samples.AutoByDate.SqlServer/Shardings/TestLogWeekVirtualRoute.cs @@ -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 + { + public override DateTime GetBeginTime() + { + return new DateTime(2021, 8, 1); + } + } +} diff --git a/samples/Samples.AutoByDate.SqlServer/Startup.cs b/samples/Samples.AutoByDate.SqlServer/Startup.cs index 02c15cd4..d828e313 100644 --- a/samples/Samples.AutoByDate.SqlServer/Startup.cs +++ b/samples/Samples.AutoByDate.SqlServer/Startup.cs @@ -43,6 +43,7 @@ namespace Samples.AutoByDate.SqlServer op.UseShardingOptionsBuilder((connection, builder) => builder.UseSqlServer(connection), (conStr,builder) => builder.UseSqlServer(conStr)); op.AddShardingTableRoute(); + op.AddShardingTableRoute(); }); services.AddChronusJob(); }