2

我正在尝试获取所有具有FiscalYear.idin的@events IList<int> years。我正在使用any(),但它引发了以下堆栈跟踪错误:

 Unrecognised method call: 
 System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable`1[TSource], System.Func`2[TSource,System.Boolean])

有任何想法吗?这是代码:

FindAllPaged(int eventTypeId, IList<int> aors, IList<int> years)
{

IList<Domain.Event> results =
    session.QueryOver<Event>()
      .Where(@event => !@event.IsDeleted && 
      @event.EventType.Id == eventTypeId &&
      years.Any(y => y == @event.FiscalYear.Id))
}
4

4 回答 4

1

看起来您正在尝试在QueryOver. 这不受支持。尝试改用 Linq 提供程序:

FindAllPaged(int eventTypeId, IList<int> aors, IList<int> years)
{

IList<Domain.Event> results =
    session.Query<Event>()
      .Where(@event => !@event.IsDeleted && 
      @event.EventType.Id == eventTypeId &&
      years.Any(y => y == @event.FiscalYear.Id))
}
于 2013-08-09T11:06:43.650 回答
1

我也遇到了同样的异常信息

无法识别的方法调用:System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable 1[TSource], System.Func2[TSource,System.Boolean])

将 IqueryOver 与 Contains 方法一起使用时

 Ex: 
var departmentTypesArray = criteria.DepartmentTypes.ToArray();
qover = qover.Where(p => departmentTypesArray.Contains(p.DepartmentType));

当我检查数据库时,我正在查询的表中没有任何记录。

当我用限制更改我的查询时,它对我有用

qover = qover.WhereRestrictionOn(p => .DepartmentType).IsIn(departmentTypesArray);
于 2016-01-26T16:57:44.720 回答
0

尝试改用该Contains方法:

IList<Domain.Event> results = session
    .QueryOver<Event>()
    .Where(e => !@event.IsDeleted && 
        @event.EventType.Id == eventTypeId &&
        years.Contains(@event.FiscalYear.Id))
    .ToList();

或者使用以下方式建立您的限制IsIn

IList<Domain.Event> results = session
    .QueryOver<Event>()
    .Where(e => !@event.IsDeleted && @event.EventType.Id == eventTypeId)
    .And(Restrictions.On<Event>(@event => @event.FiscalYear.Id)
                     .IsIn(years.ToArray()))
    .ToList();
于 2013-08-08T20:52:21.687 回答
-1

你可以试试这个:

IList<Domain.Event> results = session.QueryOver<Event>().ToList().FindAll(e => !e.IsDeleted && e.Id.Equals(eventTypeId) && years.Contains(e.FiscalYear.Id))
于 2013-08-09T09:53:11.450 回答