优化多字段分片下的默认检查属性导致的属性不存在问题
This commit is contained in:
parent
a2008bce88
commit
618f973e8f
|
@ -151,6 +151,7 @@ namespace Sample.MySql
|
||||||
builder
|
builder
|
||||||
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
||||||
.UseLoggerFactory(efLogger);
|
.UseLoggerFactory(efLogger);
|
||||||
|
builder.AddInterceptors()
|
||||||
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||||
// .UseLoggerFactory(loggerFactory1)
|
// .UseLoggerFactory(loggerFactory1)
|
||||||
// .EnableSensitiveDataLogging();
|
// .EnableSensitiveDataLogging();
|
||||||
|
@ -241,6 +242,7 @@ namespace Sample.MySql
|
||||||
app.ApplicationServices.UseAutoTryCompensateTable();
|
app.ApplicationServices.UseAutoTryCompensateTable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext<DefaultShardingDbContext>>();
|
// var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext<DefaultShardingDbContext>>();
|
||||||
// var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
// var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||||
// var connectionString = virtualDataSource.GetConnectionString("dataSourceName");
|
// var connectionString = virtualDataSource.GetConnectionString("dataSourceName");
|
||||||
|
|
|
@ -122,16 +122,19 @@ namespace ShardingCore.Core.EntityMetadatas
|
||||||
{
|
{
|
||||||
if (_shardingConfigOptions.CheckShardingKeyValueGenerated)
|
if (_shardingConfigOptions.CheckShardingKeyValueGenerated)
|
||||||
{
|
{
|
||||||
|
var propertiesMap = efEntityType.GetProperties().ToDictionary(o=>o.Name,o=>o);
|
||||||
if (metadata.IsMultiDataSourceMapping)
|
if (metadata.IsMultiDataSourceMapping)
|
||||||
{
|
{
|
||||||
foreach (var metadataProperty in metadata.ShardingDataSourceProperties)
|
foreach (var metadataProperty in metadata.ShardingDataSourceProperties)
|
||||||
{
|
{
|
||||||
var propertyName = metadataProperty.Key;
|
var propertyName = metadataProperty.Key;
|
||||||
var property = efEntityType.GetProperty(propertyName);
|
if (propertiesMap.TryGetValue(propertyName, out var property))
|
||||||
if (property.ValueGenerated != ValueGenerated.Never)
|
|
||||||
{
|
{
|
||||||
throw new ShardingCoreConfigException(
|
if (property.ValueGenerated != ValueGenerated.Never)
|
||||||
$"sharding data source key:{propertyName} is not {nameof(ValueGenerated)}.{nameof(ValueGenerated.Never)}");
|
{
|
||||||
|
throw new ShardingCoreConfigException(
|
||||||
|
$"sharding data source key:{propertyName} is not {nameof(ValueGenerated)}.{nameof(ValueGenerated.Never)}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,11 +144,13 @@ namespace ShardingCore.Core.EntityMetadatas
|
||||||
foreach (var metadataProperty in metadata.ShardingTableProperties)
|
foreach (var metadataProperty in metadata.ShardingTableProperties)
|
||||||
{
|
{
|
||||||
var propertyName = metadataProperty.Key;
|
var propertyName = metadataProperty.Key;
|
||||||
var property = efEntityType.GetProperty(propertyName);
|
if (propertiesMap.TryGetValue(propertyName, out var property))
|
||||||
if (property.ValueGenerated != ValueGenerated.Never)
|
|
||||||
{
|
{
|
||||||
throw new ShardingCoreConfigException(
|
if (property.ValueGenerated != ValueGenerated.Never)
|
||||||
$"sharding table key:{propertyName} is not {nameof(ValueGenerated)}.{nameof(ValueGenerated.Never)}");
|
{
|
||||||
|
throw new ShardingCoreConfigException(
|
||||||
|
$"sharding table key:{propertyName} is not {nameof(ValueGenerated)}.{nameof(ValueGenerated.Never)}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue