Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Extensions/Xtensive.Orm.BulkOperations/Internals/QueryOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Xtensive.Core;
using Xtensive.Orm.Linq;
using Xtensive.Orm.Model;
using Xtensive.Orm.Providers;
using Xtensive.Reflection;
using Xtensive.Sql;
using Xtensive.Sql.Dml;
Expand All @@ -19,6 +20,7 @@ internal abstract class QueryOperation<T> : Operation<T>
where T : class, IEntity
{
private static readonly ConstantExpression ComplexConditionConstant = Expression.Constant(IncludeAlgorithm.ComplexCondition);
private static readonly ConstantExpression AutoConditionConstant = Expression.Constant(IncludeAlgorithm.Auto);

protected IQueryable<T> query;

Expand Down Expand Up @@ -54,13 +56,19 @@ protected override int ExecuteInternal()

if (algorithm == IncludeAlgorithm.Auto) {
var arguments = ex.Arguments.ToList();
arguments[1] = ComplexConditionConstant;
ex = Expression.Call(methodInfo, arguments);

if (!CanUseTvp(ex.Arguments[0].Type)) {
arguments[1] = ComplexConditionConstant;
ex = Expression.Call(methodInfo, arguments);
}
}
}
else {
var arguments = ex.Arguments.ToList();
arguments.Insert(1, ComplexConditionConstant);
var conditionConstant = CanUseTvp(ex.Arguments[0].Type)
? AutoConditionConstant
: ComplexConditionConstant;
arguments.Insert(1, AutoConditionConstant);
ex = Expression.Call(WellKnownMembers.InMethod.MakeGenericMethod(methodInfo.GetGenericArguments()), arguments);
}
}
Expand All @@ -73,6 +81,10 @@ protected override int ExecuteInternal()

#region Non-public methods

private bool CanUseTvp(Type fieldType) =>
(fieldType == typeof(long) || fieldType == typeof(int) || fieldType == typeof(string))
&& DomainHandler.Handlers.ProviderInfo.Supports(ProviderFeatures.TableValuedParameters);

protected abstract SqlTableRef GetStatementTable(SqlStatement statement);
protected abstract SqlExpression GetStatementWhere(SqlStatement statement);

Expand Down