This commit is contained in:
xuejiaming 2021-11-08 21:49:43 +08:00
parent 9ca0507e1e
commit 57d11dff5a
4 changed files with 16 additions and 4 deletions

View File

@ -1,8 +1,8 @@
:start
::定义版本
set EFCORE2=2.3.1.29
set EFCORE3=3.3.1.29
set EFCORE5=5.3.1.29
set EFCORE2=2.3.1.30
set EFCORE3=3.3.1.30
set EFCORE5=5.3.1.30
::删除所有bin与obj下的文件
@echo off

View File

@ -61,7 +61,7 @@ namespace ShardingCore.Extensions
}
else
{
var comparer = Activator.CreateInstance(typeof(InMemoryShardingComparer<>).GetGenericType0(selectorResultType), shardingComparer);
var comparer = shardingComparer.CreateComparer(selectorResultType);
resultExp = Expression.Call(typeof(Queryable), methodName,
new Type[] { type, selectorResultType },
source.Expression, Expression.Quote(selector),Expression.Constant(comparer));

View File

@ -13,6 +13,7 @@ namespace ShardingCore.Sharding.Abstractions
public interface IShardingComparer
{
int Compare(IComparable a, IComparable b,bool asc);
object CreateComparer(Type comparerType);
}
public interface IShardingComparer<TShardingDbContext> : IShardingComparer where TShardingDbContext:DbContext,IShardingDbContext

View File

@ -1,7 +1,9 @@
using System;
using System.Collections.Concurrent;
using Microsoft.EntityFrameworkCore;
using ShardingCore.Extensions;
using ShardingCore.Sharding.Abstractions;
using ShardingCore.Sharding.Internals;
namespace ShardingCore.Sharding
{
@ -13,9 +15,18 @@ namespace ShardingCore.Sharding
*/
public class CSharpLanguageShardingComparer<TShardingDbContext>:IShardingComparer<TShardingDbContext> where TShardingDbContext:DbContext,IShardingDbContext
{
private readonly ConcurrentDictionary<Type, object> _comparers = new ConcurrentDictionary<Type, object>();
public int Compare(IComparable x, IComparable y, bool asc)
{
return x.SafeCompareToWith(y, asc);
}
public object CreateComparer(Type comparerType)
{
var comparer = _comparers.GetOrAdd(comparerType,
key => Activator.CreateInstance(typeof(InMemoryShardingComparer<>).GetGenericType0(comparerType),
this));
return comparer;
}
}
}