public IEnumerable<UserReadNews> GetLatestUserReadNews(IEnumerable<string> userIds)
{
IQuery query = Session.CreateQuery("from UserReadNews as j where j.FacebookUser_id in (:userIds)");
query.SetParameterList("userIds", userIds );
return query.List();
}
I have this method where I want to return this data as lazily as possible, because I am determining which data to show and then stopping. I don’t want the whole query to be executed against the whole table.
My concern is the List() method. is this lazy or eager?
Can I call this method from another method and yield break when I’m done with what I need?
I agree with @CSharper about only querying what you absolutely need.
If you still need to make this as lazy as possible after that optimization, use
ICriteria.Future<T>()instead ofICriteria.List<T>():Futurewill give you an actual IEnumerable with deferred querying instead of a whole list right off the bat. It will sometimes optimize queries too when given the chance.