修复dynamicshardinghelper的创建库的bug导致默认对象也会创建 发布x.6.0.7
This commit is contained in:
parent
3699ccf426
commit
36b844da19
|
@ -13,7 +13,7 @@ namespace ShardingCore6x
|
||||||
public void Configure(EntityTypeBuilder<Order> builder)
|
public void Configure(EntityTypeBuilder<Order> builder)
|
||||||
{
|
{
|
||||||
builder.HasKey(o => o.Id);
|
builder.HasKey(o => o.Id);
|
||||||
builder.Property(o => o.Id).IsUnicode(false).HasMaxLength(50);
|
builder.Property(o => o.Id).ValueGeneratedOnAdd().IsUnicode(false).HasMaxLength(50);
|
||||||
builder.Property(o => o.Body).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
|
builder.Property(o => o.Body).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
|
||||||
builder.Property(o => o.Remark).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
|
builder.Property(o => o.Remark).IsRequired().HasDefaultValue(string.Empty).HasMaxLength(128);
|
||||||
builder.Property(o => o.Payer).IsRequired().IsUnicode(false).HasMaxLength(50);
|
builder.Property(o => o.Payer).IsRequired().IsUnicode(false).HasMaxLength(50);
|
||||||
|
|
|
@ -9,6 +9,7 @@ using ShardingCore.Core;
|
||||||
using ShardingCore.Core.RuntimeContexts;
|
using ShardingCore.Core.RuntimeContexts;
|
||||||
using ShardingCore.EFCores;
|
using ShardingCore.EFCores;
|
||||||
using ShardingCore.Extensions;
|
using ShardingCore.Extensions;
|
||||||
|
using ShardingCore.Helpers;
|
||||||
using ShardingCore.TableExists;
|
using ShardingCore.TableExists;
|
||||||
using ShardingCore.TableExists.Abstractions;
|
using ShardingCore.TableExists.Abstractions;
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,7 @@ namespace ShardingCore.Extensions
|
||||||
#if EFCORE6
|
#if EFCORE6
|
||||||
var contextModelRelationalModel = contextModel.GetRelationalModel() as RelationalModel;
|
var contextModelRelationalModel = contextModel.GetRelationalModel() as RelationalModel;
|
||||||
var valueTuples =
|
var valueTuples =
|
||||||
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => entityMetadataManager.IsShardingTable(m.EntityType.ClrType) ||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList();
|
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => !entityMetadataManager.IsShardingDataSource(m.EntityType.ClrType) ||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList();
|
||||||
for (int i = 0; i < valueTuples.Count; i++)
|
for (int i = 0; i < valueTuples.Count; i++)
|
||||||
{
|
{
|
||||||
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
||||||
|
@ -134,7 +134,7 @@ namespace ShardingCore.Extensions
|
||||||
#if EFCORE5
|
#if EFCORE5
|
||||||
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
|
var contextModelRelationalModel = contextModel.RelationalModel as RelationalModel;
|
||||||
var valueTuples =
|
var valueTuples =
|
||||||
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => entityMetadataManager.IsShardingTable(m.EntityType.ClrType)||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList();
|
contextModelRelationalModel.Tables.Where(o => o.Value.EntityTypeMappings.Any(m => !entityMetadataManager.IsShardingDataSource(m.EntityType.ClrType)||entityMetadataManager.TryGet(m.EntityType.ClrType)==null)).Select(o => o.Key).ToList();
|
||||||
for (int i = 0; i < valueTuples.Count; i++)
|
for (int i = 0; i < valueTuples.Count; i++)
|
||||||
{
|
{
|
||||||
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
contextModelRelationalModel.Tables.Remove(valueTuples[i]);
|
||||||
|
@ -143,7 +143,7 @@ namespace ShardingCore.Extensions
|
||||||
#if EFCORE2 || EFCORE3
|
#if EFCORE2 || EFCORE3
|
||||||
var entityTypes =
|
var entityTypes =
|
||||||
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
|
contextModel.GetFieldValue("_entityTypes") as SortedDictionary<string, EntityType>;
|
||||||
var list = entityTypes.Where(o => entityMetadataManager.IsShardingTable(o.Value.ClrType) || entityMetadataManager.TryGet(o.Value.ClrType) == null).Select(o => o.Key).ToList();
|
var list = entityTypes.Where(o => !entityMetadataManager.IsShardingDataSource(o.Value.ClrType) || entityMetadataManager.TryGet(o.Value.ClrType) == null).Select(o => o.Key).ToList();
|
||||||
for (int i = 0; i < list.Count; i++)
|
for (int i = 0; i < list.Count; i++)
|
||||||
{
|
{
|
||||||
entityTypes.Remove(list[i]);
|
entityTypes.Remove(list[i]);
|
||||||
|
|
|
@ -124,7 +124,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
return callExpression;
|
return callExpression;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据属性求和
|
/// 根据属性求和
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <param name="property"></param>
|
/// <param name="property"></param>
|
||||||
|
@ -141,7 +141,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
return source.Provider.Execute<TSelect>(callExpression);
|
return source.Provider.Execute<TSelect>(callExpression);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据属性求和
|
/// 根据属性求和
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
/// <param name="propertyName"></param>
|
/// <param name="propertyName"></param>
|
||||||
|
@ -156,7 +156,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
return source.SumByProperty(property);
|
return source.SumByProperty(property);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 对
|
/// 对
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TSelect"></typeparam>
|
/// <typeparam name="TSelect"></typeparam>
|
||||||
/// <param name="source"></param>
|
/// <param name="source"></param>
|
||||||
|
@ -290,12 +290,12 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
return source.Provider.Execute(callExpression);
|
return source.Provider.Execute(callExpression);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取平均数和 [{avg1,count1},{avg2,count2}....]=>sum(avg1...n*count1...n)/sum(count1...n)
|
/// 获取平均数和 [{avg1,count1},{avg2,count2}....]=>sum(avg1...n*count1...n)/sum(count1...n)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">数据源</param>
|
/// <param name="source">数据源</param>
|
||||||
/// <param name="averagePropertyName">聚合函数average属性名</param>
|
/// <param name="averagePropertyName">聚合函数average属性名</param>
|
||||||
/// <param name="countPropertyName">聚合函数count属性名</param>
|
/// <param name="countPropertyName">聚合函数count属性名</param>
|
||||||
/// <param name="resultType">平均值返回结果:int/int=double</param>
|
/// <param name="resultType">平均值返回结果:int/int=double</param>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public static object AverageWithCount(this IQueryable source, string averagePropertyName, string countPropertyName, Type resultType)
|
public static object AverageWithCount(this IQueryable source, string averagePropertyName, string countPropertyName, Type resultType)
|
||||||
{
|
{
|
||||||
|
@ -311,7 +311,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
if (source == null) throw new ArgumentNullException(nameof(source));
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
if (averageProperty == null) throw new ArgumentNullException(nameof(averageProperty));
|
if (averageProperty == null) throw new ArgumentNullException(nameof(averageProperty));
|
||||||
if (countProperty == null) throw new ArgumentNullException(nameof(countProperty));
|
if (countProperty == null) throw new ArgumentNullException(nameof(countProperty));
|
||||||
//获取sum
|
//获取sum
|
||||||
var sum = source.AverageSum(averageProperty, countProperty);
|
var sum = source.AverageSum(averageProperty, countProperty);
|
||||||
var count = source.SumByProperty(countProperty);
|
var count = source.SumByProperty(countProperty);
|
||||||
return AverageConstant(sum, count,resultType);
|
return AverageConstant(sum, count,resultType);
|
||||||
|
@ -327,11 +327,11 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
Expression constantSum = Expression.Constant(sum);
|
Expression constantSum = Expression.Constant(sum);
|
||||||
//如果计算类型和返回类型不一致先转成一致
|
//如果计算类型和返回类型不一致先转成一致
|
||||||
if(sum.GetType()!=resultType)
|
if(sum.GetType()!=resultType)
|
||||||
constantSum = Expression.Convert(constantSum, resultType);
|
constantSum = Expression.Convert(constantSum, resultType);
|
||||||
Expression constantCount = Expression.Constant(count);
|
Expression constantCount = Expression.Constant(count);
|
||||||
//如果计算类型和返回类型不一致先转成一致
|
//如果计算类型和返回类型不一致先转成一致
|
||||||
if (count.GetType() != resultType)
|
if (count.GetType() != resultType)
|
||||||
constantCount = Expression.Convert(constantCount, resultType);
|
constantCount = Expression.Convert(constantCount, resultType);
|
||||||
var binaryExpression = Expression.Divide(constantSum, constantCount);
|
var binaryExpression = Expression.Divide(constantSum, constantCount);
|
||||||
|
@ -342,11 +342,11 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
{
|
{
|
||||||
var resultType = typeof(TResult);
|
var resultType = typeof(TResult);
|
||||||
Expression constantSum = Expression.Constant(sum);
|
Expression constantSum = Expression.Constant(sum);
|
||||||
//如果计算类型和返回类型不一致先转成一致
|
//如果计算类型和返回类型不一致先转成一致
|
||||||
if (sum.GetType() != resultType)
|
if (sum.GetType() != resultType)
|
||||||
constantSum = Expression.Convert(constantSum, resultType);
|
constantSum = Expression.Convert(constantSum, resultType);
|
||||||
Expression constantCount = Expression.Constant(count);
|
Expression constantCount = Expression.Constant(count);
|
||||||
//如果计算类型和返回类型不一致先转成一致
|
//如果计算类型和返回类型不一致先转成一致
|
||||||
if (count.GetType() != resultType)
|
if (count.GetType() != resultType)
|
||||||
constantCount = Expression.Convert(constantCount, resultType);
|
constantCount = Expression.Convert(constantCount, resultType);
|
||||||
var binaryExpression = Expression.Divide(constantSum, constantCount);
|
var binaryExpression = Expression.Divide(constantSum, constantCount);
|
||||||
|
@ -368,12 +368,12 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
//}
|
//}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取平均数和 [{avg1,sum1},{avg2,sum2}....]=>sum(sum1...n)/sum(sum1...n/avg1...n)
|
/// 获取平均数和 [{avg1,sum1},{avg2,sum2}....]=>sum(sum1...n)/sum(sum1...n/avg1...n)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">数据源</param>
|
/// <param name="source">数据源</param>
|
||||||
/// <param name="averagePropertyName">聚合函数average属性名</param>
|
/// <param name="averagePropertyName">聚合函数average属性名</param>
|
||||||
/// <param name="sumPropertyName">聚合函数sum属性名</param>
|
/// <param name="sumPropertyName">聚合函数sum属性名</param>
|
||||||
/// <param name="resultType">平均值返回结果:int/int=double</param>
|
/// <param name="resultType">平均值返回结果:int/int=double</param>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public static object AverageWithSum(this IQueryable source, string averagePropertyName, string sumPropertyName, Type resultType)
|
public static object AverageWithSum(this IQueryable source, string averagePropertyName, string sumPropertyName, Type resultType)
|
||||||
{
|
{
|
||||||
|
@ -394,11 +394,11 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
return AverageConstant(sum, count, resultType);
|
return AverageConstant(sum, count, resultType);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取平均数和 [{avg1,count1},{avg2,count2}....]=>sum(avg1...n*count1...n)/sum(count1...n)
|
/// 获取平均数和 [{avg1,count1},{avg2,count2}....]=>sum(avg1...n*count1...n)/sum(count1...n)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">数据源</param>
|
/// <param name="source">数据源</param>
|
||||||
/// <param name="averageProperty">聚合函数average属性名</param>
|
/// <param name="averageProperty">聚合函数average属性名</param>
|
||||||
/// <param name="countProperty">聚合函数count属性名</param>
|
/// <param name="countProperty">聚合函数count属性名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static object AverageSum(this IQueryable source, PropertyInfo averageProperty, PropertyInfo countProperty)
|
private static object AverageSum(this IQueryable source, PropertyInfo averageProperty, PropertyInfo countProperty)
|
||||||
{
|
{
|
||||||
|
@ -411,7 +411,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
MemberExpression averageMember = Expression.MakeMemberAccess(parameter, averageProperty);
|
MemberExpression averageMember = Expression.MakeMemberAccess(parameter, averageProperty);
|
||||||
//o.count
|
//o.count
|
||||||
MemberExpression countMember = Expression.MakeMemberAccess(parameter, countProperty);
|
MemberExpression countMember = Expression.MakeMemberAccess(parameter, countProperty);
|
||||||
//Convert(o.count,o.avg.GetType()) 必须要同类型才能计算
|
//Convert(o.count,o.avg.GetType()) 必须要同类型才能计算
|
||||||
var countConvertExpression = Expression.Convert(countMember, averageProperty.PropertyType);
|
var countConvertExpression = Expression.Convert(countMember, averageProperty.PropertyType);
|
||||||
//o.avg*Convert(o.count,o.avg.GetType())
|
//o.avg*Convert(o.count,o.avg.GetType())
|
||||||
var multiply = Expression.Multiply(averageMember, countConvertExpression);
|
var multiply = Expression.Multiply(averageMember, countConvertExpression);
|
||||||
|
@ -434,11 +434,11 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取平均数个数 [{avg1,sum1},{avg2,sum2}....]=>sum(sum1..n)/sum(sum1...n/avg1...n)
|
/// 获取平均数个数 [{avg1,sum1},{avg2,sum2}....]=>sum(sum1..n)/sum(sum1...n/avg1...n)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="source">数据源</param>
|
/// <param name="source">数据源</param>
|
||||||
/// <param name="averageProperty">聚合函数average属性名</param>
|
/// <param name="averageProperty">聚合函数average属性名</param>
|
||||||
/// <param name="sumProperty">聚合函数count属性名</param>
|
/// <param name="sumProperty">聚合函数count属性名</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static object AverageCount(this IQueryable source, PropertyInfo averageProperty, PropertyInfo sumProperty)
|
private static object AverageCount(this IQueryable source, PropertyInfo averageProperty, PropertyInfo sumProperty)
|
||||||
{
|
{
|
||||||
|
@ -451,7 +451,7 @@ namespace ShardingCore.Sharding.Enumerators.AggregateExtensions
|
||||||
MemberExpression averageMember = Expression.MakeMemberAccess(parameter, averageProperty);
|
MemberExpression averageMember = Expression.MakeMemberAccess(parameter, averageProperty);
|
||||||
//o.sum
|
//o.sum
|
||||||
MemberExpression sumMember = Expression.MakeMemberAccess(parameter, sumProperty);
|
MemberExpression sumMember = Expression.MakeMemberAccess(parameter, sumProperty);
|
||||||
//Convert(o.sum,o.avg.GetType()) 必须要同类型才能计算
|
//Convert(o.sum,o.avg.GetType()) 必须要同类型才能计算
|
||||||
var sumConvertExpression = Expression.Convert(sumMember, averageProperty.PropertyType);
|
var sumConvertExpression = Expression.Convert(sumMember, averageProperty.PropertyType);
|
||||||
//Convert(o.sum,o.avg.GetType())/o.avg
|
//Convert(o.sum,o.avg.GetType())/o.avg
|
||||||
var divide = Expression.Divide(sumConvertExpression, averageMember);
|
var divide = Expression.Divide(sumConvertExpression, averageMember);
|
||||||
|
|
Loading…
Reference in New Issue