修复代理模式下的bug

This commit is contained in:
xuejiaming 2022-10-31 23:33:26 +08:00
parent 9485ae03c1
commit c4069b1919
3 changed files with 8 additions and 1 deletions

View File

@ -324,7 +324,7 @@ namespace ShardingCore.Extensions
public static TEntity GetAttachedEntity<TEntity>(this DbContext context, TEntity entity) where TEntity:class
{
if (entity == null) { throw new ArgumentNullException(nameof(entity)); }
var entityPrimaryKey = context.Model.FindEntityType(entity.GetType()).FindPrimaryKey();
var entityPrimaryKey = context.Model.FindRuntimeEntityType(entity.GetType()).FindPrimaryKey();
if (entityPrimaryKey == null)
{
return entity;

View File

@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="6.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.1" />
<PackageReference Include="xunit" Version="2.4.2" />

View File

@ -19,6 +19,12 @@ namespace ShardingCore.Test
{
}
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
//{
// base.OnConfiguring(optionsBuilder);
// optionsBuilder.UseLazyLoadingProxies();
//}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);