Question

I am trying to get all @events where that have a FiscalYear.id inIList<int> years. I am using any() but it is throwing the following stacktrace error:

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

Any Ideas? Here is the code:

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))
}
Was it helpful?

Solution 3

Try using the Contains method instead:

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

Or build your restrictions the long way using 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();

OTHER TIPS

Looks like you are trying to use a Linq method in QueryOver. This isn't supported. Try using the Linq provider instead:

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))
}

I also encountered the same exception message

Unrecognised method call: System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable1[TSource], System.Func2[TSource,System.Boolean])

when using IqueryOver with Contains method

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

when i check the database, i don't have any records inside the table that i am making query.

when i changed my query with Restrictions, then it works for me

qover = qover.WhereRestrictionOn(p => .DepartmentType).IsIn(departmentTypesArray);

You could try this:

IList<Domain.Event> results = session.QueryOver<Event>().ToList().FindAll(e => !e.IsDeleted && e.Id.Equals(eventTypeId) && years.Contains(e.FiscalYear.Id))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top