修改为新logo

This commit is contained in:
xuejiaming 2022-01-18 11:22:12 +08:00
parent dfd276080a
commit 1615492c4d
10 changed files with 142 additions and 57 deletions

View File

@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<img height="140" src="https://xuejm.gitee.io/sharding-core-doc/logo.svg"> <img height="340" src="https://xuejm.gitee.io/sharding-core-doc/logo.svg">
</p> </p>
# ShardingCore # ShardingCore

View File

@ -1,5 +1,5 @@
<p align="center"> <p align="center">
<img height="140" src="https://xuejmnet.github.io/sharding-core-doc/logo.svg"> <img height="340" src="https://xuejmnet.github.io/sharding-core-doc/logo.svg">
</p> </p>
# ShardingCore # ShardingCore

View File

@ -1,9 +1,9 @@
:start :start
::定义版本 ::定义版本
set EFCORE2=2.4.0.02 set EFCORE2=2.4.0.03
set EFCORE3=3.4.0.02 set EFCORE3=3.4.0.03
set EFCORE5=5.4.0.02 set EFCORE5=5.4.0.03
set EFCORE6=6.4.0.02 set EFCORE6=6.4.0.03
::删除所有bin与obj下的文件 ::删除所有bin与obj下的文件
@echo off @echo off

View File

@ -11,6 +11,8 @@ namespace Sample.MySql.DbContexts
{ {
public DefaultShardingDbContext(DbContextOptions<DefaultShardingDbContext> options) : base(options) public DefaultShardingDbContext(DbContextOptions<DefaultShardingDbContext> options) : base(options)
{ {
//切记不要在构造函数中使用会让模型提前创建的方法
//ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
} }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)

View File

@ -9,14 +9,6 @@
} }
}, },
"profiles": { "profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Sample.MySql": { "Sample.MySql": {
"commandName": "Project", "commandName": "Project",
"launchBrowser": true, "launchBrowser": true,

View File

@ -1,11 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src3x\ShardingCore.3x\ShardingCore.3x.csproj" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ShardingCore\ShardingCore.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,14 +1,23 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Sample.MySql.DbContexts;
using Sample.MySql.Shardings;
using ShardingCore;
using ShardingCore.TableExists;
namespace Sample.MySql namespace Sample.MySql
{ {
public class Startup public class Startup
{ {
public static readonly ILoggerFactory efLogger = LoggerFactory.Create(builder =>
{
builder.AddFilter((category, level) => category == DbLoggerCategory.Database.Command.Name && level == LogLevel.Information).AddConsole();
});
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)
{ {
Configuration = configuration; Configuration = configuration;
@ -30,6 +39,33 @@ namespace Sample.MySql
// op.AddShardingTableRoute<SysUserModVirtualTableRoute>(); // op.AddShardingTableRoute<SysUserModVirtualTableRoute>();
// op.AddShardingTableRoute<SysUserSalaryVirtualTableRoute>(); // op.AddShardingTableRoute<SysUserSalaryVirtualTableRoute>();
// }); // });
services.AddShardingDbContext<DefaultShardingDbContext>(ServiceLifetime.Transient, ServiceLifetime.Transient)
.AddEntityConfig(o =>
{
o.CreateShardingTableOnStart = true;
o.EnsureCreatedWithOutShardingTable = true;
o.AddShardingTableRoute<SysUserLogByMonthRoute>();
o.AddShardingTableRoute<SysUserModVirtualTableRoute>();
o.UseShardingQuery((conStr, builder) =>
{
builder.UseMySql(conStr, new MySqlServerVersion(new Version())).UseLoggerFactory(efLogger);
//builder.UseMySql(conStr, new MySqlServerVersion(new Version()));
});
o.UseShardingTransaction((connection, builder) =>
{
builder.UseMySql(connection, new MySqlServerVersion(new Version())).UseLoggerFactory(efLogger);
});
})
.AddConfig(op =>
{
op.ConfigId = "c1";
op.AddDefaultDataSource("ds0",
"server=127.0.0.1;port=3306;database=dbxxxx;userid=root;password=L6yBtV6qNENrwBy7;");
//op.AddDefaultDataSource("ds0", "server=127.0.0.1;port=3306;database=db2;userid=root;password=L6yBtV6qNENrwBy7;")
op.ReplaceTableEnsureManager(sp=>new MySqlTableEnsureManager<DefaultShardingDbContext>());
}).EnsureConfig();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -31,7 +31,7 @@ namespace Sample.SqlServer
using (var scope = app.ApplicationServices.CreateScope()) using (var scope = app.ApplicationServices.CreateScope())
{ {
var virtualDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>(); var virtualDbContext = scope.ServiceProvider.GetService<DefaultShardingDbContext>();
if (!virtualDbContext.Set<SysUserMod>().Any()) if (!virtualDbContext.Set<SysUserMod>().Any(o=>o.Id=="111"))
{ {
var ids = Enumerable.Range(1, 1000); var ids = Enumerable.Range(1, 1000);
var userMods = new List<SysUserMod>(); var userMods = new List<SysUserMod>();

View File

@ -131,52 +131,102 @@ namespace ShardingCore.Core.Internal.Visitors
private object GetShardingKeyValue(Expression expression) private object GetShardingKeyValue(Expression expression)
{ {
if (expression is ConstantExpression constantExpression) if (expression == null)
return null;
switch (expression)
{ {
return constantExpression.Value; case ConstantExpression e:
} return e.Value;
if (expression is UnaryExpression unaryExpression)
{
return Expression.Lambda(unaryExpression.Operand).Compile().DynamicInvoke();
}
if (expression is MemberExpression member1Expression) case MemberExpression e when e.Member is FieldInfo field:
{ return field.GetValue(
GetShardingKeyValue(
e.Expression
)
);
if (member1Expression.Expression is ConstantExpression memberConstantExpression) case MemberExpression e when e.Member is PropertyInfo property:
{ return property.GetValue(
if (member1Expression.Member is FieldInfo memberFieldInfo) GetShardingKeyValue(
e.Expression
)
);
case ListInitExpression e when e.NewExpression.Arguments.Count() == 0:
var collection = e.NewExpression.Constructor.Invoke(new object[0]);
foreach (var i in e.Initializers)
{ {
object container = memberConstantExpression.Value; i.AddMethod.Invoke(
return memberFieldInfo.GetValue(container); collection,
i.Arguments
.Select(
a => GetShardingKeyValue(a)
)
.ToArray()
);
} }
if (member1Expression.Member is PropertyInfo memberPropertyInfo) return collection;
{
object container = memberConstantExpression.Value;
return memberPropertyInfo.GetValue(container);
}
else
{
return memberConstantExpression.Value;
}
}
return Expression.Lambda(member1Expression).Compile().DynamicInvoke();
}
if (expression is MethodCallExpression methodCallExpression) case MethodCallExpression e:
{ return e.Method.Invoke(
return Expression.Lambda(methodCallExpression).Compile().DynamicInvoke(); GetShardingKeyValue(e.Object),
//return methodCallExpression.Method.Invoke( e.Arguments
// GetShardingKeyValue(methodCallExpression.Object), .Select(
// methodCallExpression.Arguments a => GetShardingKeyValue(a)
// .Select( )
// a => GetShardingKeyValue(a) .ToArray()
// ) );
// .ToArray()
//);
}
throw new ShardingCoreException("cant get value " + expression); default:
//TODO: better messaging
throw new ShardingCoreException("cant get value " + expression);
}
//if (expression is ConstantExpression constantExpression)
//{
// return constantExpression.Value;
//}
//if (expression is UnaryExpression unaryExpression)
//{
// return Expression.Lambda(unaryExpression.Operand).Compile().DynamicInvoke();
//}
//if (expression is MemberExpression member1Expression)
//{
// if (member1Expression.Expression is ConstantExpression memberConstantExpression)
// {
// if (member1Expression.Member is FieldInfo memberFieldInfo)
// {
// object container = memberConstantExpression.Value;
// return memberFieldInfo.GetValue(container);
// }
// if (member1Expression.Member is PropertyInfo memberPropertyInfo)
// {
// object container = memberConstantExpression.Value;
// return memberPropertyInfo.GetValue(container);
// }
// else
// {
// return memberConstantExpression.Value;
// }
// }
// return Expression.Lambda(member1Expression).Compile().DynamicInvoke();
//}
//if (expression is MethodCallExpression methodCallExpression)
//{
// return Expression.Lambda(methodCallExpression).Compile().DynamicInvoke();
// //return methodCallExpression.Method.Invoke(
// // GetShardingKeyValue(methodCallExpression.Object),
// // methodCallExpression.Arguments
// // .Select(
// // a => GetShardingKeyValue(a)
// // )
// // .ToArray()
// //);
//}
//throw new ShardingCoreException("cant get value " + expression);
} }
protected override Expression VisitMethodCall(MethodCallExpression node) protected override Expression VisitMethodCall(MethodCallExpression node)

View File

@ -47,7 +47,6 @@ namespace ShardingCore.Utils
/// <summary> /// <summary>
/// 分表路由过滤 /// 分表路由过滤
/// </summary> /// </summary>
/// <typeparam name="TKey"></typeparam>
/// <param name="queryable"></param> /// <param name="queryable"></param>
/// <param name="entityMetadata"></param> /// <param name="entityMetadata"></param>
/// <param name="keyToTailExpression"></param> /// <param name="keyToTailExpression"></param>