升级到7.6.0.8移除IShardingModelCacheOption,将默认的缓存设置进行了建议配置

This commit is contained in:
xuejiaming 2022-11-27 00:00:09 +08:00
parent 9de612b37f
commit ff307db879
18 changed files with 119 additions and 203 deletions

View File

@ -1,10 +1,10 @@
:start :start
::定义版本 ::定义版本
set EFCORE7=7.7.0.7 set EFCORE7=7.7.0.8
set EFCORE6=7.6.0.7 set EFCORE6=7.6.0.8
set EFCORE5=7.5.0.7 set EFCORE5=7.5.0.8
set EFCORE3=7.3.0.7 set EFCORE3=7.3.0.8
set EFCORE2=7.2.0.7 set EFCORE2=7.2.0.8
::删除所有bin与obj下的文件 ::删除所有bin与obj下的文件
@echo off @echo off

View File

@ -34,16 +34,22 @@ namespace Sample.MySql.Shardings
builder.ShardingProperty(o => o.Time); builder.ShardingProperty(o => o.Time);
} }
// protected override List<TableRouteUnit> AfterShardingRouteUnitFilter(DataSourceRouteResult dataSourceRouteResult, List<TableRouteUnit> shardingRouteUnits)
// {
// if (shardingRouteUnits.Count > 10)
// {
// _logger.LogInformation("截断前:"+string.Join(",",shardingRouteUnits.Select(o=>o.Tail)));
// //这边你要自己做顺序处理阶段
// var result= shardingRouteUnits.OrderByDescending(o=>o.Tail).Take(10).ToList();
// _logger.LogInformation("截断后:"+string.Join(",",result.Select(o=>o.Tail)));
// return result;
// }
// return base.AfterShardingRouteUnitFilter(dataSourceRouteResult, shardingRouteUnits);
// }
protected override List<TableRouteUnit> AfterShardingRouteUnitFilter(DataSourceRouteResult dataSourceRouteResult, List<TableRouteUnit> shardingRouteUnits) protected override List<TableRouteUnit> AfterShardingRouteUnitFilter(DataSourceRouteResult dataSourceRouteResult, List<TableRouteUnit> shardingRouteUnits)
{ {
if (shardingRouteUnits.Count > 10) Console.WriteLine("AfterShardingRouteUnitFilter:"+shardingRouteUnits.Count);
{
_logger.LogInformation("截断前:"+string.Join(",",shardingRouteUnits.Select(o=>o.Tail)));
//这边你要自己做顺序处理阶段
var result= shardingRouteUnits.OrderByDescending(o=>o.Tail).Take(10).ToList();
_logger.LogInformation("截断后:"+string.Join(",",result.Select(o=>o.Tail)));
return result;
}
return base.AfterShardingRouteUnitFilter(dataSourceRouteResult, shardingRouteUnits); return base.AfterShardingRouteUnitFilter(dataSourceRouteResult, shardingRouteUnits);
} }
} }

View File

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
namespace ShardingCore.Core
{
/// <summary>
///
/// </summary>
/// Author: xjm
/// Created: 2022/4/15 11:40:58
/// Email: 326308290@qq.com
public interface IShardingModelCacheOption
{
#if !EFCORE2
CacheItemPriority GetModelCachePriority();
int GetModelCacheEntrySize();
#endif
int GetModelCacheLockObjectSeconds();
}
}

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Extensions.Caching.Memory;
using ShardingCore.Core.ShardingConfigurations; using ShardingCore.Core.ShardingConfigurations;
using ShardingCore.Exceptions; using ShardingCore.Exceptions;
@ -26,6 +27,23 @@ namespace ShardingCore.Core.ModelCacheLockerProviders
_locks.Add(new object()); _locks.Add(new object());
} }
} }
public int GetModelCacheLockObjectSeconds()
{
return _shardingConfigOptions.ModelCacheLockObjectSeconds;
}
#if !EFCORE2
public CacheItemPriority GetCacheItemPriority()
{
return _shardingConfigOptions.CacheItemPriority;
}
public int GetCacheEntrySize()
{
return _shardingConfigOptions.CacheEntrySize;
}
#endif
public object GetCacheLockObject(object modelCacheKey) public object GetCacheLockObject(object modelCacheKey)
{ {
if (modelCacheKey == null) if (modelCacheKey == null)

View File

@ -1,7 +1,16 @@
using Microsoft.Extensions.Caching.Memory;
namespace ShardingCore.Core.ModelCacheLockerProviders namespace ShardingCore.Core.ModelCacheLockerProviders
{ {
public interface IModelCacheLockerProvider public interface IModelCacheLockerProvider
{ {
int GetModelCacheLockObjectSeconds();
#if !EFCORE2
CacheItemPriority GetCacheItemPriority();
int GetCacheEntrySize();
#endif
object GetCacheLockObject(object modelCacheKey); object GetCacheLockObject(object modelCacheKey);
} }
} }

View File

@ -3,6 +3,7 @@ using ShardingCore.Sharding.ReadWriteConfigurations;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data.Common; using System.Data.Common;
using Microsoft.Extensions.Caching.Memory;
using ShardingCore.Core.ServiceProviders; using ShardingCore.Core.ServiceProviders;
namespace ShardingCore.Core.ShardingConfigurations namespace ShardingCore.Core.ShardingConfigurations
@ -12,6 +13,20 @@ namespace ShardingCore.Core.ShardingConfigurations
/// </summary> /// </summary>
public class ShardingConfigOptions public class ShardingConfigOptions
{ {
/// <summary>
/// 模型缓存锁等待时间
/// </summary>
public int ModelCacheLockObjectSeconds { get; set; } = 3;
#if !EFCORE2
/// <summary>
/// 模型缓存的优先级
/// </summary>
public CacheItemPriority CacheItemPriority { get; set; } = CacheItemPriority.High;
/// <summary>
/// efcore缓存最多限制10240个单个缓存size设置为10那么就意味可以最多统一时间缓存1024个(缓存过期了那么还是会可以缓存进去的)
/// </summary>
public int CacheEntrySize { get; set; } = 10;
#endif
/// <summary> /// <summary>
/// 模型缓存锁等级 /// 模型缓存锁等级
/// </summary> /// </summary>

View File

@ -58,16 +58,13 @@ namespace ShardingCore.EFCores
} }
} }
int waitSeconds = 3;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context); var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!_models.TryGetValue(cacheKey, out var model)) if (!_models.TryGetValue(cacheKey, out var model))
{ {
if (context is IShardingModelCacheOption shardingModelCacheOption) var modelCacheLockerProvider = _shardingRuntimeContext.GetModelCacheLockerProvider();
{ var waitSeconds = modelCacheLockerProvider.GetModelCacheLockObjectSeconds();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds(); var cacheLockObject = modelCacheLockerProvider.GetCacheLockObject(cacheKey);
}
var cacheLockObject = _shardingRuntimeContext.GetModelCacheLockerProvider().GetCacheLockObject(cacheKey);
var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds)); var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire) if (!acquire)
{ {

View File

@ -49,9 +49,7 @@ namespace ShardingCore.EFCores
DbContext context, DbContext context,
IConventionSetBuilder conventionSetBuilder) IConventionSetBuilder conventionSetBuilder)
{ {
var priority = CacheItemPriority.High; CacheItemPriority? setPriority = null;
var size = 200;
var waitSeconds = 3;
if (context is IShardingTableDbContext shardingTableDbContext) if (context is IShardingTableDbContext shardingTableDbContext)
{ {
if (shardingTableDbContext.RouteTail is null) if (shardingTableDbContext.RouteTail is null)
@ -65,22 +63,19 @@ namespace ShardingCore.EFCores
} }
else if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail && singleQueryRouteTail.IsShardingTableQuery()) else if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail && singleQueryRouteTail.IsShardingTableQuery())
{ {
priority = CacheItemPriority.Normal; setPriority = CacheItemPriority.Normal;
} }
} }
var cache = Dependencies.MemoryCache; var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context); var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!cache.TryGetValue(cacheKey, out IModel model)) if (!cache.TryGetValue(cacheKey, out IModel model))
{ {
if (context is IShardingModelCacheOption shardingModelCacheOption)
{ var modelCacheLockerProvider = _shardingRuntimeContext.GetModelCacheLockerProvider();
priority = shardingModelCacheOption.GetModelCachePriority(); var priority = setPriority ?? modelCacheLockerProvider.GetCacheItemPriority();
size = shardingModelCacheOption.GetModelCacheEntrySize(); var size = modelCacheLockerProvider.GetCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds(); var waitSeconds = modelCacheLockerProvider.GetModelCacheLockObjectSeconds();
} var cacheLockObject = modelCacheLockerProvider.GetCacheLockObject(cacheKey);
// Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var cacheLockObject = _shardingRuntimeContext.GetModelCacheLockerProvider().GetCacheLockObject(cacheKey);
var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds)); var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire) if (!acquire)
{ {

View File

@ -66,9 +66,7 @@ namespace ShardingCore.EFCores
ModelDependencies modelDependencies) ModelDependencies modelDependencies)
{ {
var priority = CacheItemPriority.High; CacheItemPriority? setPriority = null;
var size = 200;
var waitSeconds = 3;
if (context is IShardingTableDbContext shardingTableDbContext) if (context is IShardingTableDbContext shardingTableDbContext)
{ {
if (shardingTableDbContext.RouteTail is null) if (shardingTableDbContext.RouteTail is null)
@ -82,20 +80,19 @@ namespace ShardingCore.EFCores
} }
else if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail&& singleQueryRouteTail.IsShardingTableQuery()) else if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail&& singleQueryRouteTail.IsShardingTableQuery())
{ {
priority = CacheItemPriority.Normal; setPriority = CacheItemPriority.Normal;
} }
} }
var cache = Dependencies.MemoryCache; var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context); var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context);
if (!cache.TryGetValue(cacheKey, out IModel model)) if (!cache.TryGetValue(cacheKey, out IModel model))
{ {
if (context is IShardingModelCacheOption shardingModelCacheOption) var modelCacheLockerProvider = _shardingRuntimeContext.GetModelCacheLockerProvider();
{
priority = shardingModelCacheOption.GetModelCachePriority(); var priority = setPriority ?? modelCacheLockerProvider.GetCacheItemPriority();
size = shardingModelCacheOption.GetModelCacheEntrySize(); var size = modelCacheLockerProvider.GetCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds(); var waitSeconds = modelCacheLockerProvider.GetModelCacheLockObjectSeconds();
} var cacheLockObject = modelCacheLockerProvider.GetCacheLockObject(cacheKey);
var cacheLockObject = _shardingRuntimeContext.GetModelCacheLockerProvider().GetCacheLockObject(cacheKey);
// Make sure OnModelCreating really only gets called once, since it may not be thread safe. // Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds)); var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire) if (!acquire)

View File

@ -10,6 +10,7 @@ using ShardingCore.Core.VirtualRoutes.TableRoutes.RouteTails.Abstractions;
using ShardingCore.Exceptions; using ShardingCore.Exceptions;
using ShardingCore.Sharding.Abstractions; using ShardingCore.Sharding.Abstractions;
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -78,9 +79,7 @@ namespace ShardingCore.EFCores
ModelCreationDependencies modelCreationDependencies, ModelCreationDependencies modelCreationDependencies,
bool designTime) bool designTime)
{ {
var priority = CacheItemPriority.High; CacheItemPriority? setPriority = null;
var size = 200;
var waitSeconds = 3;
if (context is IShardingTableDbContext shardingTableDbContext) if (context is IShardingTableDbContext shardingTableDbContext)
{ {
if (shardingTableDbContext.RouteTail is null) if (shardingTableDbContext.RouteTail is null)
@ -96,21 +95,19 @@ namespace ShardingCore.EFCores
else else
if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail && singleQueryRouteTail.IsShardingTableQuery()) if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail && singleQueryRouteTail.IsShardingTableQuery())
{ {
priority = CacheItemPriority.Normal; setPriority = CacheItemPriority.Normal;
} }
} }
var cache = Dependencies.MemoryCache; var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context, designTime); var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context, designTime);
if (!cache.TryGetValue(cacheKey, out IModel model)) if (!cache.TryGetValue(cacheKey, out IModel model))
{ {
if (context is IShardingModelCacheOption shardingModelCacheOption) var modelCacheLockerProvider = _shardingRuntimeContext.GetModelCacheLockerProvider();
{
priority = shardingModelCacheOption.GetModelCachePriority();
size = shardingModelCacheOption.GetModelCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds();
}
var cacheLockObject = _shardingRuntimeContext.GetModelCacheLockerProvider().GetCacheLockObject(cacheKey); var priority = setPriority ?? modelCacheLockerProvider.GetCacheItemPriority();
var size = modelCacheLockerProvider.GetCacheEntrySize();
var waitSeconds = modelCacheLockerProvider.GetModelCacheLockObjectSeconds();
var cacheLockObject = modelCacheLockerProvider.GetCacheLockObject(cacheKey);
// Make sure OnModelCreating really only gets called once, since it may not be thread safe. // Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds)); var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire) if (!acquire)
@ -138,35 +135,6 @@ namespace ShardingCore.EFCores
return model; return model;
} }
// public IModelCacheKeyFactory GetModelCacheKeyFactory()
// {
// return Dependencies.ModelCacheKeyFactory;
// }
//
// public object GetSyncObject()
// {
// return _syncObject;
// }
// public void Remove(object key)
// {
// var acquire = Monitor.TryEnter(_syncObject, TimeSpan.FromSeconds(3));
// if (!acquire)
// {
// throw new ShardingCoreInvalidOperationException("cache model timeout");
// }
// try
// {
//
// var cache = Dependencies.MemoryCache;
// cache.Remove(key);
// }
// finally
// {
// Monitor.Exit(_syncObject);
// }
// }
} }
} }
#endif #endif

View File

@ -1,5 +1,4 @@
 #if EFCORE7
#if EFCORE7
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata;
@ -14,12 +13,12 @@ using ShardingCore.Core.RuntimeContexts;
namespace ShardingCore.EFCores namespace ShardingCore.EFCores
{ {
public class ShardingModelSource : ModelSource public class ShardingModelSource : ModelSource
{ {
private readonly IShardingRuntimeContext _shardingRuntimeContext; private readonly IShardingRuntimeContext _shardingRuntimeContext;
public ShardingModelSource(ModelSourceDependencies dependencies,IShardingRuntimeContext shardingRuntimeContext) : base(dependencies) public ShardingModelSource(ModelSourceDependencies dependencies, IShardingRuntimeContext shardingRuntimeContext)
: base(dependencies)
{ {
_shardingRuntimeContext = shardingRuntimeContext; _shardingRuntimeContext = shardingRuntimeContext;
Check.NotNull(dependencies, nameof(dependencies)); Check.NotNull(dependencies, nameof(dependencies));
@ -44,55 +43,60 @@ namespace ShardingCore.EFCores
ModelCreationDependencies modelCreationDependencies, ModelCreationDependencies modelCreationDependencies,
bool designTime) bool designTime)
{ {
var priority = CacheItemPriority.High; CacheItemPriority? setPriority = null;
var size = 200;
var waitSeconds = 3;
if (context is IShardingTableDbContext shardingTableDbContext) if (context is IShardingTableDbContext shardingTableDbContext)
{ {
if (shardingTableDbContext.RouteTail is null) if (shardingTableDbContext.RouteTail is null)
{ {
throw new ShardingCoreInvalidOperationException("db context model is inited before RouteTail set value"); throw new ShardingCoreInvalidOperationException(
"db context model is inited before RouteTail set value");
} }
if (shardingTableDbContext.RouteTail is INoCacheRouteTail) if (shardingTableDbContext.RouteTail is INoCacheRouteTail)
{ {
var noCacheModel = this.CreateModel(context, modelCreationDependencies.ConventionSetBuilder, modelCreationDependencies.ModelDependencies); var noCacheModel = this.CreateModel(context, modelCreationDependencies.ConventionSetBuilder,
noCacheModel = modelCreationDependencies.ModelRuntimeInitializer.Initialize(noCacheModel, designTime, modelCreationDependencies.ValidationLogger); modelCreationDependencies.ModelDependencies);
noCacheModel = modelCreationDependencies.ModelRuntimeInitializer.Initialize(noCacheModel,
designTime, modelCreationDependencies.ValidationLogger);
return noCacheModel; return noCacheModel;
} }
else else if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail &&
if (shardingTableDbContext.RouteTail is ISingleQueryRouteTail singleQueryRouteTail && singleQueryRouteTail.IsShardingTableQuery()) singleQueryRouteTail.IsShardingTableQuery())
{ {
priority = CacheItemPriority.Normal; setPriority = CacheItemPriority.Normal;
} }
} }
var cache = Dependencies.MemoryCache; var cache = Dependencies.MemoryCache;
var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context, designTime); var cacheKey = Dependencies.ModelCacheKeyFactory.Create(context, designTime);
if (!cache.TryGetValue(cacheKey, out IModel model)) if (!cache.TryGetValue(cacheKey, out IModel model))
{ {
if (context is IShardingModelCacheOption shardingModelCacheOption) var modelCacheLockerProvider = _shardingRuntimeContext.GetModelCacheLockerProvider();
{
priority = shardingModelCacheOption.GetModelCachePriority(); var priority = setPriority ?? modelCacheLockerProvider.GetCacheItemPriority();
size = shardingModelCacheOption.GetModelCacheEntrySize(); var size = modelCacheLockerProvider.GetCacheEntrySize();
waitSeconds = shardingModelCacheOption.GetModelCacheLockObjectSeconds(); var waitSeconds = modelCacheLockerProvider.GetModelCacheLockObjectSeconds();
} var cacheLockObject = modelCacheLockerProvider.GetCacheLockObject(cacheKey);
var cacheLockObject = _shardingRuntimeContext.GetModelCacheLockerProvider().GetCacheLockObject(cacheKey);
// Make sure OnModelCreating really only gets called once, since it may not be thread safe. // Make sure OnModelCreating really only gets called once, since it may not be thread safe.
var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds)); var acquire = Monitor.TryEnter(cacheLockObject, TimeSpan.FromSeconds(waitSeconds));
if (!acquire) if (!acquire)
{ {
throw new ShardingCoreInvalidOperationException("cache model timeout"); throw new ShardingCoreInvalidOperationException("cache model timeout");
} }
try try
{ {
if (!cache.TryGetValue(cacheKey, out model)) if (!cache.TryGetValue(cacheKey, out model))
{ {
model = CreateModel( model = CreateModel(
context, modelCreationDependencies.ConventionSetBuilder, modelCreationDependencies.ModelDependencies); context, modelCreationDependencies.ConventionSetBuilder,
modelCreationDependencies.ModelDependencies);
model = modelCreationDependencies.ModelRuntimeInitializer.Initialize( model = modelCreationDependencies.ModelRuntimeInitializer.Initialize(
model, designTime, modelCreationDependencies.ValidationLogger); model, designTime, modelCreationDependencies.ValidationLogger);
model = cache.Set(cacheKey, model, new MemoryCacheEntryOptions { Size = size, Priority = priority }); model = cache.Set(cacheKey, model,
new MemoryCacheEntryOptions { Size = size, Priority = priority });
} }
} }
finally finally

View File

@ -1,17 +0,0 @@
// using System;
// using System.Collections.Generic;
// using System.Linq;
// using System.Text;
// using System.Threading.Tasks;
// using Microsoft.EntityFrameworkCore.Infrastructure;
//
// namespace ShardingCore.EFCores
// {
// public interface IShardingModelSource
// {
// IModelCacheKeyFactory GetModelCacheKeyFactory();
// object GetSyncObject();
// void Remove(object key);
//
// }
// }

View File

@ -311,58 +311,6 @@ namespace ShardingCore.Extensions
RemoveDbContextRelationModelSaveOnlyThatIsNamedType(dbContext, typeof(T)); RemoveDbContextRelationModelSaveOnlyThatIsNamedType(dbContext, typeof(T));
} }
/// <summary>
/// 移除模型缓存
/// </summary>
/// <param name="dbContext"></param>
// public static void RemoveModelCache(this DbContext dbContext)
// {
// #if !EFCORE2 && !EFCORE3 && !EFCORE5 && !EFCORE6 && !EFCORE7
// throw new NotImplementedException();
// #endif
// #if EFCORE6 || EFCORE7
// var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
// var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();
// object key1 = modelCacheKeyFactory.Create(dbContext,true);
// shardingModelSource.Remove(key1);
// object key2 = modelCacheKeyFactory.Create(dbContext,false);
// shardingModelSource.Remove(key2);
// #endif
// #if EFCORE5
// var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
// var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();
// object key1 = modelCacheKeyFactory.Create(dbContext);
// shardingModelSource.Remove(key1);
// #endif
// #if EFCORE3
//
// var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
// var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();
// object key1 = modelCacheKeyFactory.Create(dbContext);
// shardingModelSource.Remove(key1);
// #endif
//
// #if EFCORE2
//
// var shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
// var modelCacheKeyFactory = shardingModelSource.GetModelCacheKeyFactory();
// object key1 = modelCacheKeyFactory.Create(dbContext);
// shardingModelSource.Remove(key1);
// #endif
// }
// /// <summary>
// /// 获取模型创建的锁
// /// </summary>
// /// <param name="dbContext"></param>
// /// <returns></returns>
// public static object GetModelCacheSyncObject(this DbContext dbContext)
// {
// IShardingModelSource shardingModelSource = dbContext.GetService<IModelSource>() as IShardingModelSource;
// return shardingModelSource.GetSyncObject();
// }
public static IEnumerable<object> GetPrimaryKeyValues<TEntity>(TEntity entity,IKey primaryKey) where TEntity : class public static IEnumerable<object> GetPrimaryKeyValues<TEntity>(TEntity entity,IKey primaryKey) where TEntity : class
{ {
return primaryKey.Properties.Select(o =>entity.GetPropertyValue(o.Name)); return primaryKey.Properties.Select(o =>entity.GetPropertyValue(o.Name));

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Version>7.7.0.7</Version> <Version>7.7.0.8</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;EFCORE7;</DefineConstants> <DefineConstants>TRACE;DEBUG;EFCORE7;</DefineConstants>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>7.2.0.7</Version> <Version>7.2.0.8</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;EFCORE2;</DefineConstants> <DefineConstants>TRACE;DEBUG;EFCORE2;</DefineConstants>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<Version>7.3.0.7</Version> <Version>7.3.0.8</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;EFCORE3;</DefineConstants> <DefineConstants>TRACE;DEBUG;EFCORE3;</DefineConstants>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Version>7.5.0.7</Version> <Version>7.5.0.8</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;EFCORE5;</DefineConstants> <DefineConstants>TRACE;DEBUG;EFCORE5;</DefineConstants>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Version>7.6.0.7</Version> <Version>7.6.0.8</Version>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<DefineConstants>TRACE;DEBUG;EFCORE6;</DefineConstants> <DefineConstants>TRACE;DEBUG;EFCORE6;</DefineConstants>
<LangVersion>9.0</LangVersion> <LangVersion>9.0</LangVersion>