I have a list of id's and I need to get all records correscponding to each id in the list .
below is the sample code
public List<Items> LoadLineItemByPkeys(IEnumerable<long> ItemId)
{
var ItemList = CurrentSession.Query<LineItem>()
.Where(l =>itemId.Contains(l.id))
.ToList();
return ItemList ;
}
but i am getting exception
An exception of type 'NHibernate.Exceptions.GenericADOException' occurred in NHibernate.dll but was not handled in user code
inner exception:-
Failed to convert parameter value from a WhereSelectArrayIterator`2 to a Int64. Please help me on this.
when i executed same query in LINQPad, i am getting the results.
You may be having trouble due to how you've passed in the IDs. You may find that converting that sequence into a list or an array would help:
// Various names to be more conventional/readable
public List<Items> LoadLineItemsById(IEnumerable<long> ids)
{
var idList = ids.ToList();
return CurrentSession.Query<LineItem>()
.Where(item => idList.Contains(item.Id))
.ToList();
}
See more on this question at Stackoverflow