多路由映射放弃模型缓存发布x.3.1.92
This commit is contained in:
parent
e029a017b7
commit
8c9d3d7f41
|
@ -1,9 +1,9 @@
|
|||
:start
|
||||
::定义版本
|
||||
set EFCORE2=2.3.1.91
|
||||
set EFCORE3=3.3.1.91
|
||||
set EFCORE5=5.3.1.91
|
||||
set EFCORE6=6.3.1.91
|
||||
set EFCORE2=2.3.1.92
|
||||
set EFCORE3=3.3.1.92
|
||||
set EFCORE5=5.3.1.92
|
||||
set EFCORE6=6.3.1.92
|
||||
|
||||
::删除所有bin与obj下的文件
|
||||
@echo off
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails
|
|||
*/
|
||||
public class MultiQueryRouteTail:IMultiQueryRouteTail
|
||||
{
|
||||
private const string RANDOM_MODEL_CACHE_KEY = "RANDOM_MODEL_CACHE_KEY";
|
||||
public const string RANDOM_MODEL_CACHE_KEY = "RANDOM_SHARDING_MODEL_CACHE_KEY";
|
||||
private readonly TableRouteResult _tableRouteResult;
|
||||
private readonly string _modelCacheKey;
|
||||
private readonly ISet<Type> _entityTypes;
|
||||
|
|
|
@ -155,6 +155,7 @@ namespace ShardingCore
|
|||
public static DbContextOptionsBuilder UseInnerDbContextSharding<TShardingDbContext>(this DbContextOptionsBuilder optionsBuilder) where TShardingDbContext : DbContext, IShardingDbContext
|
||||
{
|
||||
return optionsBuilder.ReplaceService<IModelCacheKeyFactory, ShardingModelCacheKeyFactory>()
|
||||
.ReplaceService<IModelSource,ShardingModelSource>()
|
||||
.ReplaceService<IModelCustomizer, ShardingModelCustomizer<TShardingDbContext>>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
|
||||
using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
|
||||
using ShardingCore.Sharding.Abstractions;
|
||||
#if !EFCORE2
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Infrastructure;
|
||||
#endif
|
||||
|
||||
namespace ShardingCore.EFCores
|
||||
{
|
||||
public class ShardingModelSource:ModelSource
|
||||
{
|
||||
public ShardingModelSource(ModelSourceDependencies dependencies) : base(dependencies)
|
||||
{
|
||||
}
|
||||
#if !EFCORE2&&!EFCORE3&&!EFCORE5&&!EFCORE6
|
||||
1
|
||||
#endif
|
||||
|
||||
#if EFCORE6
|
||||
|
||||
public override IModel GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, bool designTime)
|
||||
{
|
||||
if (context is IShardingTableDbContext shardingTableDbContext)
|
||||
{
|
||||
if (shardingTableDbContext.RouteTail is IMultiQueryRouteTail)
|
||||
{
|
||||
var model = this.CreateModel(context, modelCreationDependencies.ConventionSetBuilder, modelCreationDependencies.ModelDependencies);
|
||||
model = modelCreationDependencies.ModelRuntimeInitializer.Initialize(model, designTime, modelCreationDependencies.ValidationLogger);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return base.GetModel(context, modelCreationDependencies, designTime);
|
||||
}
|
||||
#endif
|
||||
#if EFCORE5
|
||||
public override IModel GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
|
||||
{
|
||||
if (context is IShardingTableDbContext shardingTableDbContext)
|
||||
{
|
||||
if (shardingTableDbContext.RouteTail is IMultiQueryRouteTail)
|
||||
{
|
||||
var model = this.CreateModel(context, conventionSetBuilder, modelDependencies);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return base.GetModel(context, conventionSetBuilder, modelDependencies);
|
||||
}
|
||||
#endif
|
||||
#if EFCORE3
|
||||
public override IModel GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
|
||||
{
|
||||
if (context is IShardingTableDbContext shardingTableDbContext)
|
||||
{
|
||||
if (shardingTableDbContext.RouteTail is IMultiQueryRouteTail)
|
||||
{
|
||||
var model = this.CreateModel(context, conventionSetBuilder);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return base.GetModel(context, conventionSetBuilder);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if EFCORE2
|
||||
public override IModel GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
|
||||
{
|
||||
if (context is IShardingTableDbContext shardingTableDbContext)
|
||||
{
|
||||
if (shardingTableDbContext.RouteTail is IMultiQueryRouteTail)
|
||||
{
|
||||
var model = this.CreateModel(context, conventionSetBuilder, validator);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return base.GetModel(context, conventionSetBuilder, validator);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -235,7 +235,7 @@ namespace ShardingCore.Extensions
|
|||
#if EFCORE2
|
||||
|
||||
var modelSource = dbContext.GetService<IModelSource>();
|
||||
var modelSourceImpl = modelSource as RelationalModelSource;
|
||||
var modelSourceImpl = modelSource as ModelSource;
|
||||
|
||||
var modelSourceDependencies =
|
||||
modelSourceImpl.GetPropertyValue("Dependencies") as ModelSourceDependencies;
|
||||
|
@ -255,23 +255,20 @@ namespace ShardingCore.Extensions
|
|||
{
|
||||
#if EFCORE6
|
||||
var dependencies = dbContext.GetService<ModelCreationDependencies>();
|
||||
var dependenciesModelSource = dependencies.ModelSource as ModelSource;
|
||||
|
||||
var syncObject = dependenciesModelSource.GetFieldValue("_syncObject");
|
||||
var syncObject = typeof(ModelSource).GetTypeFieldValue(dependencies.ModelSource, "_syncObject");
|
||||
return syncObject;
|
||||
#endif
|
||||
#if EFCORE5
|
||||
var dependencies = dbContext.GetService<IModelCreationDependencies>();
|
||||
var dependenciesModelSource = dependencies.ModelSource as ModelSource;
|
||||
|
||||
var syncObject = dependenciesModelSource.GetFieldValue("_syncObject");
|
||||
var syncObject = typeof(ModelSource).GetTypeFieldValue(dependencies.ModelSource, "_syncObject");
|
||||
return syncObject;
|
||||
#endif
|
||||
#if EFCORE3
|
||||
var modelSource = dbContext.GetService<IModelSource>();
|
||||
var modelSourceImpl = modelSource as ModelSource;
|
||||
|
||||
var syncObject = modelSourceImpl.GetFieldValue("_syncObject");
|
||||
var syncObject = typeof(ModelSource).GetTypeFieldValue(modelSource, "_syncObject");
|
||||
return syncObject;
|
||||
#endif
|
||||
#if EFCORE2
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace ShardingCore.Sharding.ShardingExecutors
|
|||
}
|
||||
public IQueryCompilerContext Create(IShardingDbContext shardingDbContext, Expression queryExpression)
|
||||
{
|
||||
IQueryCompilerContext queryCompilerContext =
|
||||
var queryCompilerContext =
|
||||
QueryCompilerContext.Create(shardingDbContext, queryExpression);
|
||||
if (queryCompilerContext.GetQueryCompilerExecutor() is not null)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue