EDIT :보다 자세한 질문.하나의 표현 트리를 다른 것으로 변환/삽입
SQL Server에서 2100 매개 변수 제한 크기를 극복하기 위해 특별히 In
쿼리에 대해 nHibernate에서 일괄 처리 작업을하고 있습니다. 이를 위해
, 나는 (이것은 매우 단순화 된 버전입니다)이 생성자를 가진 클래스를 만들었습니다
이BatchedQuery(session.Query<Foo>(), allValues, (l, e) => l.Contains(e.Id));
...
public BatchedQuery(IQueryable<TEntity> query, IList<TValue> allValues, Expression<Func<IList<TValue>, TEntity, bool>> predicate)
{
List<TValue> values = ...; // Select a batch from allValues
...
// I want to pass the values to the expression passed in...
// something like this, without using Compile:
// e => predicate.Compile()(values, e)
// using JKor's method, I tried this...
ParameterExpression param = Expression.Parameter(typeof(TEntity), "e");
Expression<Func<TEntity, bool>> expr2 =
Expression.Lambda<Func<TEntity, bool>>(Expression.Invoke(predicate,
Expression.Constant(batchOfValues), param), param);
query = query.Where(expr2);
// Do something with the query...
}
// Somewhere else..
// This causes the exception
batchedQuery.ToList();
위의 원인이되는 nHibernate 수는 KeyNotFoundException
을 던져.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at NHibernate.Param.NamedParameterSpecification.SetEffectiveType(QueryParameters queryParameters)
at NHibernate.Param.ParametersBackTrackExtensions.ResetEffectiveExpectedType(IEnumerable`1 parameterSpecs, QueryParameters queryParameters)
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.ResetEffectiveExpectedType(IEnumerable`1 parameterSpecs, QueryParameters queryParameters)
at NHibernate.Loader.Loader.CreateSqlCommand(QueryParameters queryParameters, ISessionImplementor session)
at NHibernate.Impl.MultiQueryImpl.AggregateQueriesInformation()
at NHibernate.Impl.MultiQueryImpl.get_Parameters()
at NHibernate.Impl.MultiQueryImpl.CreateCombinedQueryParameters()
at NHibernate.Impl.MultiQueryImpl.List()
at NHibernate.Impl.FutureQueryBatch.GetResultsFrom(IMultiQuery multiApproach)
at NHibernate.Impl.FutureBatch`2.GetResults()
at NHibernate.Impl.FutureBatch`2.get_Results()
at NHibernate.Impl.FutureBatch`2.GetCurrentResult[TResult](Int32 currentIndex)
at NHibernate.Impl.FutureBatch`2.<>c__DisplayClass4`1.<GetEnumerator>b__3()
at NHibernate.Impl.DelayedEnumerator`1.<get_Enumerable>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at NovusERP.Data.Helpers.BatchedQuery`2.ToList() in D:\Short Utilities\Novus\NovusERP\NovusERP.Data\Helpers\BatchedQuery.cs:line 63
at NovusERP.Modules.Payroll.Attendance.AttendanceViewModel.GetEmployees(IList`1 selectedEmployeeIds) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceViewModel.cs:line 79
at NovusERP.Modules.Payroll.Attendance.AttendanceViewModel..ctor(MonthYear currentMonth, IList`1 selectedEmployeeIds) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceViewModel.cs:line 47
at NovusERP.Modules.Payroll.Attendance.AttendanceView..ctor(MonthYear currentMonth, IList`1 selectedEmployees) in D:\Short Utilities\Novus\NovusERP\NovusERP.Modules\Payroll\Attendance\AttendanceView.xaml.cs:line 18
at lambda_method(Closure , Object[])
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
이 사람이 올바른 방향으로 날 포인트 :
다음 는 스택 추적입니까? 어떤 도움을 주시면 감사하겠습니다.
감사합니다.
Yogesh.
감사합니다. 나 좀 가자. 어떤 방법이 있어도, 원래의 expr'에서'l'을 대체 할 수 있습니까? 나는'Invoke'를 호출하지 않고 expr2를 만드는 것을 의미합니까? – Yogesh
이론에서는 가능하지만 전체 표현식 트리를 다시 작성하고 값을 대체해야합니다. 'Expression.Invoke'는 단지'InvocationExpression'을 생성합니다. 이 정확한 예제에서는 대체를하기 위해 이렇게 할 수 있습니다 : 'expr2 = Expression.Lambda> ((expr1.Body as MethodCallExpression) .Update (Expression.Constant (values), expr1.Parameters [ 0]), expr1.Parameters [0])' 그리고'param'을 정의하는 라인을 삭제하십시오 –
JKor