@@ -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