2021-08-19 15:25:11 +08:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2021-09-24 10:11:39 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* 描述:
|
|
|
|
|
*
|
|
|
|
|
* Author:xuejiaming
|
|
|
|
|
* Created: 2020/12/28 13:58:46
|
|
|
|
|
**/
|
2021-08-18 21:47:26 +08:00
|
|
|
|
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-18 21:47:26 +08:00
|
|
|
|
{
|
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
|
|
|
|
|
2021-10-03 14:09:01 +08:00
|
|
|
|
|
2021-09-21 11:33:41 +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-18 21:47:26 +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-17 23:05:36 +08:00
|
|
|
|
{
|
2021-08-20 22:07:44 +08:00
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2021-08-17 23:05:36 +08:00
|
|
|
|
|
2021-09-21 11:33:41 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if EFCORE2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public IAsyncEnumerable<TResult> ExecuteAsync<TResult>(Expression query)
|
|
|
|
|
{
|
|
|
|
|
return _shardingQueryExecutor.ExecuteAsync<IAsyncEnumerable<TResult>>(_currentContext, query);
|
2021-10-03 14:09:01 +08:00
|
|
|
|
|
2021-09-21 11:33:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<TResult> ExecuteAsync<TResult>(Expression query, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _shardingQueryExecutor.ExecuteAsync<Task<TResult>>(_currentContext, query, cancellationToken);
|
2021-10-03 14:09:01 +08:00
|
|
|
|
|
2021-09-21 11:33:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|