2021-11-03 08:48:24 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2021-10-07 04:53:54 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
|
using ShardingCore.Core;
|
|
|
|
|
using ShardingCore.VirtualRoutes.Months;
|
2021-11-03 08:48:24 +08:00
|
|
|
|
using System;
|
2021-11-18 13:29:58 +08:00
|
|
|
|
using ShardingCore.Core.EntityMetadatas;
|
2021-10-07 04:53:54 +08:00
|
|
|
|
|
|
|
|
|
namespace Sample.Migrations.EFCores
|
|
|
|
|
{
|
2021-11-18 13:29:58 +08:00
|
|
|
|
public class ShardingWithDateTime
|
2021-10-07 04:53:54 +08:00
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public int Age { get; set; }
|
|
|
|
|
public DateTime CreateTime { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ShardingWithDateTimeMap : IEntityTypeConfiguration<ShardingWithDateTime>
|
|
|
|
|
{
|
|
|
|
|
public void Configure(EntityTypeBuilder<ShardingWithDateTime> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.HasKey(o => o.Id);
|
|
|
|
|
builder.Property(o => o.Id).IsRequired().IsUnicode(false).HasMaxLength(128);
|
|
|
|
|
builder.Property(o => o.Name).HasMaxLength(128);
|
|
|
|
|
builder.ToTable(nameof(ShardingWithDateTime));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class ShardingWithDateTimeVirtualTableRoute : AbstractSimpleShardingMonthKeyDateTimeVirtualTableRoute<ShardingWithDateTime>
|
|
|
|
|
{
|
|
|
|
|
public override DateTime GetBeginTime()
|
|
|
|
|
{
|
|
|
|
|
return new DateTime(2021, 9, 1);
|
|
|
|
|
}
|
2021-11-18 13:29:58 +08:00
|
|
|
|
|
|
|
|
|
public override void Configure(EntityMetadataTableBuilder<ShardingWithDateTime> builder)
|
|
|
|
|
{
|
|
|
|
|
builder.ShardingProperty(o => o.CreateTime);
|
|
|
|
|
}
|
2021-10-07 04:53:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|