Skip to content

Commit 3699ccf

Browse files
committed
提交并发布x.6.0.6
1 parent 8645580 commit 3699ccf

File tree

15 files changed

+250
-22
lines changed

15 files changed

+250
-22
lines changed

ShardingCore.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.AutoCreateIfPresent"
6565
EndProject
6666
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShardingCore.CommonTest", "test\ShardingCore.CommonTest\ShardingCore.CommonTest.csproj", "{3E895438-E609-4860-8391-6897ED55DA06}"
6767
EndProject
68+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.ShardingConsole", "samples\Sample.ShardingConsole\Sample.ShardingConsole.csproj", "{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8}"
69+
EndProject
6870
Global
6971
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7072
Debug|Any CPU = Debug|Any CPU
@@ -167,6 +169,10 @@ Global
167169
{3E895438-E609-4860-8391-6897ED55DA06}.Debug|Any CPU.Build.0 = Debug|Any CPU
168170
{3E895438-E609-4860-8391-6897ED55DA06}.Release|Any CPU.ActiveCfg = Release|Any CPU
169171
{3E895438-E609-4860-8391-6897ED55DA06}.Release|Any CPU.Build.0 = Release|Any CPU
172+
{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
173+
{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
174+
{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
175+
{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8}.Release|Any CPU.Build.0 = Release|Any CPU
170176
EndGlobalSection
171177
GlobalSection(SolutionProperties) = preSolution
172178
HideSolutionNode = FALSE
@@ -196,6 +202,7 @@ Global
196202
{D839D632-4AE4-4F75-8A2C-49EE029B0787} = {EDF8869A-C1E1-491B-BC9F-4A33F4DE1C73}
197203
{40C83D48-0614-4651-98C6-2ABBE857D83D} = {EDF8869A-C1E1-491B-BC9F-4A33F4DE1C73}
198204
{3E895438-E609-4860-8391-6897ED55DA06} = {CC2C88C0-65F2-445D-BE78-973B840FE281}
205+
{BAB101D4-2BFF-44CE-90E3-8B72DDB266B8} = {EDF8869A-C1E1-491B-BC9F-4A33F4DE1C73}
199206
EndGlobalSection
200207
GlobalSection(ExtensibilityGlobals) = postSolution
201208
SolutionGuid = {8C07A667-E8B4-43C7-8053-721584BAD291}

nuget-publish.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
:start
22
::定义版本
3-
set EFCORE2=2.6.0.5
4-
set EFCORE3=3.6.0.5
5-
set EFCORE5=5.6.0.5
6-
set EFCORE6=6.6.0.5
3+
set EFCORE2=2.6.0.6
4+
set EFCORE3=3.6.0.6
5+
set EFCORE5=5.6.0.6
6+
set EFCORE6=6.6.0.6
77

88
::删除所有bin与obj下的文件
99
@echo off

samples/Sample.MySql/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public void ConfigureServices(IServiceCollection services)
7171
o.AddShardingTableRoute<SysUserModVirtualTableRoute>();
7272
o.AddShardingDataSourceRoute<SysUserModVirtualDataSourceRoute>();
7373
}).UseConfig(o =>
74-
{
74+
{
75+
o.ThrowIfQueryRouteNotMatch = false;
7576
o.UseShardingQuery((conStr,builder)=>
7677
{
7778
builder.UseMySql(conStr, new MySqlServerVersion(new Version()))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
3+
using ShardingCore.Sharding;
4+
using ShardingCore.Sharding.Abstractions;
5+
6+
namespace Sample.ShardingConsole;
7+
8+
public class MyDbContext:AbstractShardingDbContext,IShardingTableDbContext
9+
{
10+
public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
11+
{
12+
}
13+
14+
protected override void OnModelCreating(ModelBuilder modelBuilder)
15+
{
16+
base.OnModelCreating(modelBuilder);
17+
modelBuilder.Entity<Order>(entity =>
18+
{
19+
entity.HasKey(o => o.Id);
20+
entity.Property(o => o.Id).IsRequired().IsUnicode(false).HasMaxLength(50);
21+
entity.Property(o=>o.Payer).IsRequired().IsUnicode(false).HasMaxLength(50);
22+
entity.Property(o => o.Area).IsRequired().IsUnicode(false).HasMaxLength(50);
23+
entity.Property(o => o.OrderStatus).HasConversion<int>();
24+
entity.ToTable(nameof(Order));
25+
});
26+
}
27+
/// <summary>
28+
/// empty impl if use sharding table
29+
/// </summary>
30+
public IRouteTail RouteTail { get; set; }
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using ShardingCore;
3+
using ShardingCore.Core.DbContextCreator;
4+
using ShardingCore.Core.ServiceProviders;
5+
6+
namespace Sample.ShardingConsole;
7+
8+
public class MyDbContextCreator:ActivatorDbContextCreator<MyDbContext>
9+
{
10+
public override DbContext GetShellDbContext(IShardingProvider shardingProvider)
11+
{
12+
var dbContextOptionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
13+
dbContextOptionsBuilder.UseDefaultSharding<MyDbContext>(ShardingProvider.ShardingRuntimeContext);
14+
return new MyDbContext(dbContextOptionsBuilder.Options);
15+
}
16+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
namespace Sample.ShardingConsole;
2+
3+
4+
/// <summary>
5+
/// order table
6+
/// </summary>
7+
public class Order
8+
{
9+
/// <summary>
10+
/// order Id
11+
/// </summary>
12+
public string Id { get; set; }
13+
/// <summary>
14+
/// payer id
15+
/// </summary>
16+
public string Payer { get; set; }
17+
/// <summary>
18+
/// pay money cent
19+
/// </summary>
20+
public long Money { get; set; }
21+
/// <summary>
22+
/// area
23+
/// </summary>
24+
public string Area { get; set; }
25+
/// <summary>
26+
/// order status
27+
/// </summary>
28+
public OrderStatusEnum OrderStatus { get; set; }
29+
/// <summary>
30+
/// CreationTime
31+
/// </summary>
32+
public DateTime CreationTime { get; set; }
33+
}
34+
public enum OrderStatusEnum
35+
{
36+
NoPay=1,
37+
Paying=2,
38+
Payed=3,
39+
PayFail=4
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using ShardingCore.Core.EntityMetadatas;
2+
using ShardingCore.VirtualRoutes.Mods;
3+
4+
namespace Sample.ShardingConsole;
5+
6+
public class OrderVirtualTableRoute:AbstractSimpleShardingModKeyStringVirtualTableRoute<Order>
7+
{
8+
public OrderVirtualTableRoute() : base(2, 3)
9+
{
10+
}
11+
12+
public override void Configure(EntityMetadataTableBuilder<Order> builder)
13+
{
14+
builder.ShardingProperty(o => o.Id);
15+
builder.AutoCreateTable(null);
16+
builder.TableSeparator("_");
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// See https://aka.ms/new-console-template for more information
2+
3+
using Microsoft.EntityFrameworkCore;
4+
using Sample.ShardingConsole;
5+
using ShardingCore;
6+
using ShardingCore.Extensions;
7+
8+
ShardingProvider.ShardingRuntimeContext.UseAutoShardingCreate();
9+
ShardingProvider.ShardingRuntimeContext.UseAutoTryCompensateTable();
10+
11+
var dbContextOptionsBuilder = new DbContextOptionsBuilder<MyDbContext>();
12+
dbContextOptionsBuilder.UseDefaultSharding<MyDbContext>(ShardingProvider.ShardingRuntimeContext);
13+
using (var dbcontext = new MyDbContext(dbContextOptionsBuilder.Options))
14+
{
15+
dbcontext.Add(new Order()
16+
{
17+
Id = Guid.NewGuid().ToString("n"),
18+
Payer = "111",
19+
Area = "123",
20+
OrderStatus = OrderStatusEnum.Payed,
21+
Money = 100,
22+
CreationTime = DateTime.Now
23+
});
24+
dbcontext.SaveChanges();
25+
}
26+
27+
Console.WriteLine("Hello, World!");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\src\ShardingCore\ShardingCore.csproj" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
16+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.Logging;
5+
using ShardingCore;
6+
using ShardingCore.Core.DbContextCreator;
7+
using ShardingCore.Core.RuntimeContexts;
8+
9+
namespace Sample.ShardingConsole;
10+
11+
public class ShardingProvider
12+
{
13+
private static ILoggerFactory efLogger = LoggerFactory.Create(builder =>
14+
{
15+
builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole();
16+
});
17+
private static readonly IShardingRuntimeContext instance;
18+
public static IShardingRuntimeContext ShardingRuntimeContext => instance;
19+
static ShardingProvider()
20+
{
21+
instance=new ShardingRuntimeBuilder<MyDbContext>().UseRouteConfig(op =>
22+
{
23+
op.AddShardingTableRoute<OrderVirtualTableRoute>();
24+
})
25+
.UseConfig((sp,op) =>
26+
{
27+
op.UseShardingQuery((con, b) =>
28+
{
29+
b.UseMySql(con, new MySqlServerVersion(new Version()))
30+
.UseLoggerFactory(efLogger);
31+
});
32+
op.UseShardingTransaction((con, b) =>
33+
{
34+
b.UseMySql(con, new MySqlServerVersion(new Version()))
35+
.UseLoggerFactory(efLogger);
36+
});
37+
op.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=console0;userid=root;password=root;");
38+
}).ReplaceService<IDbContextCreator, MyDbContextCreator>(ServiceLifetime.Singleton).Build();
39+
}
40+
}

0 commit comments

Comments
 (0)