Skip to content

Commit

Permalink
Re-adds byte-array translation post-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
svengeance committed Jan 24, 2020
1 parent 96ffe14 commit 2f5fc99
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method
if (method.IsGenericMethod
&& arguments[0].Type == typeof(byte[]))
{
var genericMethodDefinition = method.GetGenericMethodDefinition();
var source = arguments[0];
var sourceTypeMapping = source.TypeMapping;

var value = arguments[1] is SqlConstantExpression constantValue
? (SqlExpression)_sqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, sourceTypeMapping)
: _sqlExpressionFactory.Convert(arguments[1], typeof(byte[]), sourceTypeMapping);

return _sqlExpressionFactory.GreaterThan(
_sqlExpressionFactory.Function(
"CHARINDEX",
new[] { value, source },
nullResultAllowed: true,
argumentsPropagateNullability: new[] { true, true },
typeof(int)),
_sqlExpressionFactory.Constant(0));
if (genericMethodDefinition == EnumerableMethods.Contains)
{
var value = arguments[1] is SqlConstantExpression constantValue
? (SqlExpression)_sqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, sourceTypeMapping)
: _sqlExpressionFactory.Convert(arguments[1], typeof(byte[]), sourceTypeMapping);

return _sqlExpressionFactory.GreaterThan(
_sqlExpressionFactory.Function(
"CHARINDEX",
new[] { value, source },
nullResultAllowed: true,
argumentsPropagateNullability: new[] { true, true },
typeof(int)),
_sqlExpressionFactory.Constant(0));
} else if (genericMethodDefinition == EnumerableMethods.SequenceEqual)
{
return _sqlExpressionFactory.Equal(source, arguments[1]);
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,30 @@ public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method

var source = arguments[0];

var value = arguments[1] is SqlConstantExpression constantValue
? (SqlExpression)_sqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, source.TypeMapping)
: _sqlExpressionFactory.Function(
"char",
new[] { arguments[1] },
nullResultAllowed: false,
argumentsPropagateNullability: new[] { false },
typeof(string));

return _sqlExpressionFactory.GreaterThan(
_sqlExpressionFactory.Function(
"instr",
new[] { source, value },
nullResultAllowed: true,
argumentsPropagateNullability: new[] { true, true },
typeof(int)),
_sqlExpressionFactory.Constant(0));
if (genericMethodDefinition == EnumerableMethods.Contains)
{
var value = arguments[1] is SqlConstantExpression constantValue
? (SqlExpression)_sqlExpressionFactory.Constant(new[] { (byte)constantValue.Value }, source.TypeMapping)
: _sqlExpressionFactory.Function(
"char",
new[] { arguments[1] },
nullResultAllowed: false,
argumentsPropagateNullability: new[] { false },
typeof(string));

return _sqlExpressionFactory.GreaterThan(
_sqlExpressionFactory.Function(
"instr",
new[] { source, value },
nullResultAllowed: true,
argumentsPropagateNullability: new[] { true, true },
typeof(int)),
_sqlExpressionFactory.Constant(0));
}
else if (genericMethodDefinition == EnumerableMethods.SequenceEqual)
{
return _sqlExpressionFactory.Equal(source, arguments[1]);
}
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7547,13 +7547,15 @@ public virtual Task Projecting_required_string_column_compared_to_null_parameter
async,
ss => ss.Set<Gear>().Select(g => g.Nickname == nullParameter));
}

public virtual Task SequenceEqual_is_translated_with_byte_array(bool isAsync)

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SequenceEqual_is_translated_with_byte_array(bool async)
{
var byteArrayParam = new byte[] { 0x04, 0x05, 0x06, 0x07, 0x08 };

return AssertQuery(
isAsync,
async,
ss => ss.Set<Squad>().Where(s => s.Banner5.SequenceEqual(byteArrayParam)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7525,6 +7525,7 @@ public override async Task Projecting_required_string_column_compared_to_null_pa
@"SELECT CAST(0 AS bit)
FROM [Gears] AS [g]
WHERE [g].[Discriminator] IN (N'Gear', N'Officer')");
}

public override async Task SequenceEqual_is_translated_with_byte_array(bool isAsync)
{
Expand Down

0 comments on commit 2f5fc99

Please sign in to comment.