sharding/samples/Sample.Migrations/EFCores/ShardingWithDateTime.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2021-11-03 08:48:24 +08:00
using Microsoft.EntityFrameworkCore;
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;
namespace Sample.Migrations.EFCores
{
2021-11-18 13:29:58 +08:00
public class ShardingWithDateTime
{
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);
}
}
}