优化多字段分片下的默认检查属性导致的属性不存在问题
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,12 +122,14 @@ 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)
|
if (property.ValueGenerated != ValueGenerated.Never)
|
||||||
{
|
{
|
||||||
throw new ShardingCoreConfigException(
|
throw new ShardingCoreConfigException(
|
||||||
|
@ -135,13 +137,15 @@ namespace ShardingCore.Core.EntityMetadatas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (metadata.IsMultiTableMapping)
|
if (metadata.IsMultiTableMapping)
|
||||||
{
|
{
|
||||||
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)
|
if (property.ValueGenerated != ValueGenerated.Never)
|
||||||
{
|
{
|
||||||
throw new ShardingCoreConfigException(
|
throw new ShardingCoreConfigException(
|
||||||
|
@ -150,6 +154,7 @@ namespace ShardingCore.Core.EntityMetadatas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
metadata.SetEntityModel(efEntityType);
|
metadata.SetEntityModel(efEntityType);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue