Skip to content

Commit 73e5946

Browse files
revert: remove MemoryExtensions.Contains handling from QueryConverter
Mindbox.Framework now normalizes MemoryExtensions.Contains to Enumerable.Contains before expressions reach data-linq, making this dead code for our stack.
1 parent d70b980 commit 73e5946

3 files changed

Lines changed: 1 addition & 176 deletions

File tree

Mindbox.Data.Linq.Tests/SqlGeneration/ArrayContainsTranslationTests.cs

Lines changed: 0 additions & 112 deletions
This file was deleted.

Mindbox.Data.Linq/Mindbox.Data.Linq.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<PublishRepositoryUrl>true</PublishRepositoryUrl>
99
<IncludeSymbols>true</IncludeSymbols>
1010
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
11-
<PackageVersion>10.8.1$(VersionTag)</PackageVersion>
11+
<PackageVersion>10.8.2$(VersionTag)</PackageVersion>
1212
<NoWarn>SYSLIB0003;SYSLIB0011</NoWarn>
1313
</PropertyGroup>
1414

Mindbox.Data.Linq/SqlClient/Query/QueryConverter.cs

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,54 +1774,6 @@ private SqlExpression GetAggregate(SqlNodeType aggType, Type clrType, SqlExpress
17741774
return new SqlUnary(aggType, clrType, sqlType, exp, this.dominatingExpression);
17751775
}
17761776

1777-
/// <summary>
1778-
/// Searches for an array of the given type in a delegate's closure.
1779-
/// Handles direct T[] fields (display class) and Object[] fields (runtime Closure),
1780-
/// including delegates nested inside Object[] fields (up to depth 3).
1781-
/// </summary>
1782-
private static object FindArrayInClosure(object target, Type arrayType, int depth = 0) {
1783-
if (target == null || depth > 3) {
1784-
return null;
1785-
}
1786-
foreach (var f in target.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) {
1787-
var val = f.GetValue(target);
1788-
if (val?.GetType() == arrayType) {
1789-
return val;
1790-
}
1791-
if (val is object[] items) {
1792-
foreach (var item in items) {
1793-
if (item?.GetType() == arrayType) {
1794-
return item;
1795-
}
1796-
if (item is Delegate nested && nested.Target != null) {
1797-
var found = FindArrayInClosure(nested.Target, arrayType, depth + 1);
1798-
if (found != null) {
1799-
return found;
1800-
}
1801-
}
1802-
}
1803-
}
1804-
}
1805-
return null;
1806-
}
1807-
1808-
private static Expression TryExtractArrayFromSpanExpression(Expression spanExpr) {
1809-
if (spanExpr is MethodCallExpression { Arguments: [var arrayExpr] }) {
1810-
return arrayExpr;
1811-
}
1812-
1813-
if (spanExpr is InvocationExpression { Arguments.Count: 0, Expression: ConstantExpression { Value: Delegate { Target: { } target } } }
1814-
&& spanExpr.Type.GetGenericArguments() is [var elementType]) {
1815-
var arrayType = elementType.MakeArrayType();
1816-
var array = FindArrayInClosure(target, arrayType);
1817-
if (array != null) {
1818-
return Expression.Constant(array, arrayType);
1819-
}
1820-
}
1821-
1822-
return null;
1823-
}
1824-
18251777
private SqlNode VisitContains(Expression sequence, Expression value) {
18261778
Type elemType = TypeSystem.GetElementType(sequence.Type);
18271779
SqlNode seqNode = this.Visit(sequence);
@@ -1927,21 +1879,6 @@ private SqlNode VisitMethodCall(MethodCallExpression mc) {
19271879
if (this.IsSequenceOperatorCall(mc)) {
19281880
return this.VisitSequenceOperatorCall(mc);
19291881
}
1930-
// In .NET 10, array.Contains(value) in expression trees compiles to
1931-
// MemoryExtensions.Contains(ReadOnlySpan<T> span, value).
1932-
// Two compiler patterns exist for the span argument:
1933-
// 1. MethodCallExpression(op_Implicit, [array]) — simple local capture
1934-
// 2. InvocationExpression(ConstantExpression(pre_compiled_delegate), []) — nested closure
1935-
// Both must be unwrapped to extract the underlying array for SQL IN translation.
1936-
else if (mc.Method.DeclaringType == typeof(MemoryExtensions)
1937-
&& mc.Method.Name == "Contains"
1938-
&& mc.Arguments[0].Type is { IsGenericType: true } spanType
1939-
&& spanType.GetGenericTypeDefinition() == typeof(ReadOnlySpan<>)) {
1940-
var arrayExpr = TryExtractArrayFromSpanExpression(mc.Arguments[0]);
1941-
if (arrayExpr != null) {
1942-
return this.VisitContains(arrayExpr, mc.Arguments[1]);
1943-
}
1944-
}
19451882
else if (IsDataManipulationCall(mc)) {
19461883
return this.VisitDataManipulationCall(mc);
19471884
}

0 commit comments

Comments
 (0)