初步打算支持include

This commit is contained in:
xuejiaming 2022-12-15 13:17:53 +08:00
parent d1e6beb9d1
commit ca0608523e
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using ShardingCore.Sharding.Abstractions;
namespace ShardingCore.EFCores
{
public class ShardingStateManager:StateManager
{
private readonly IShardingDbContext _currentShardingDbContext;
public ShardingStateManager(StateManagerDependencies dependencies) : base(dependencies)
{
_currentShardingDbContext = (IShardingDbContext)dependencies.CurrentContext;
}
public override InternalEntityEntry GetOrCreateEntry(object entity)
{
var genericDbContext = _currentShardingDbContext.CreateGenericDbContext(entity);
var dbContextDependencies = genericDbContext.GetService<IDbContextDependencies>();
var stateManager = dbContextDependencies.StateManager;
return stateManager.GetOrCreateEntry(entity);
}
public override InternalEntityEntry GetOrCreateEntry(object entity, IEntityType entityType)
{
var genericDbContext = _currentShardingDbContext.CreateGenericDbContext(entity);
var dbContextDependencies = genericDbContext.GetService<IDbContextDependencies>();
var stateManager = dbContextDependencies.StateManager;
return stateManager.GetOrCreateEntry(entity,entityType);
}
}
}