sharding/src/ShardingCore/EFCores/ShardingQueryCompiler.cs

96 lines
2.8 KiB
C#
Raw Normal View History

2021-08-19 15:25:11 +08:00
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
2021-01-26 10:18:49 +08:00
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.Internal;
2021-08-17 22:17:18 +08:00
using ShardingCore.Sharding.Abstractions;
2021-08-19 09:22:12 +08:00
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
2021-01-26 10:18:49 +08:00
2021-08-20 22:07:44 +08:00
2021-01-26 10:18:49 +08:00
namespace ShardingCore.EFCores
{
/**
*
*
* Authorxuejiaming
* Created: 2020/12/28 13:58:46
**/
public class ShardingQueryCompiler : IQueryCompiler
2021-08-17 22:17:18 +08:00
{
private readonly ICurrentDbContext _currentContext;
2021-09-01 17:34:57 +08:00
private readonly IShardingQueryExecutor _shardingQueryExecutor;
2021-01-26 10:18:49 +08:00
2021-08-19 15:25:11 +08:00
public ShardingQueryCompiler(ICurrentDbContext currentContext)
{
2021-08-17 22:17:18 +08:00
_currentContext = currentContext;
2021-09-01 17:34:57 +08:00
_shardingQueryExecutor = ShardingContainer.GetService<IShardingQueryExecutor>();
2021-08-17 22:17:18 +08:00
}
public TResult Execute<TResult>(Expression query)
{
2021-09-01 17:34:57 +08:00
return _shardingQueryExecutor.Execute<TResult>(_currentContext, query);
2021-08-17 22:17:18 +08:00
}
2021-08-20 22:07:44 +08:00
#if !EFCORE2
2021-08-17 22:17:18 +08:00
public TResult ExecuteAsync<TResult>(Expression query, CancellationToken cancellationToken)
{
2021-09-01 17:34:57 +08:00
return _shardingQueryExecutor.ExecuteAsync<TResult>(_currentContext, query, cancellationToken);
2021-08-17 22:17:18 +08:00
}
2021-08-20 22:07:44 +08:00
public Func<QueryContext, TResult> CreateCompiledQuery<TResult>(Expression query)
{
throw new NotImplementedException();
}
2021-08-17 22:17:18 +08:00
2021-08-20 22:07:44 +08:00
public Func<QueryContext, Task<TResult>> CreateCompiledAsyncTaskQuery<TResult>(Expression query)
{
throw new NotImplementedException();
}
2021-08-17 22:17:18 +08:00
2021-08-20 22:07:44 +08:00
public Func<QueryContext, TResult> CreateCompiledAsyncQuery<TResult>(Expression query)
{
2021-08-20 22:07:44 +08:00
throw new NotImplementedException();
}
#endif
#if EFCORE2
public IAsyncEnumerable<TResult> ExecuteAsync<TResult>(Expression query)
{
return _shardingQueryExecutor.ExecuteAsync<IAsyncEnumerable<TResult>>(_currentContext, query);
}
public Task<TResult> ExecuteAsync<TResult>(Expression query, CancellationToken cancellationToken)
{
return _shardingQueryExecutor.ExecuteAsync<Task<TResult>>(_currentContext, query, cancellationToken);
}
public Func<QueryContext, TResult> CreateCompiledQuery<TResult>(Expression query)
{
throw new NotImplementedException();
}
public Func<QueryContext, IAsyncEnumerable<TResult>> CreateCompiledAsyncEnumerableQuery<TResult>(Expression query)
{
throw new NotImplementedException();
}
public Func<QueryContext, Task<TResult>> CreateCompiledAsyncTaskQuery<TResult>(Expression query)
{
throw new NotImplementedException();
}
#endif
2021-08-20 22:07:44 +08:00
2021-08-17 22:17:18 +08:00
}
}