Reputation: 98
I have old code to support. NHibernate is used to query DB. There are NHibernate LINQ queries like IQueryOver.Where
and others. It works fine but I want to use these queries for local sequences. In Microsoft LINQ there is the method Enumerable.AsQueryable
. Is there any analogue in NHibernate LINQ?
So I have this.
private IQueryOver<Package> GetPackages(GetPackageMessage message)
{
var query = SessionFactory.Current.QueryOver<Package>();
if (message.TzapUtc.Use)
{
query = query.Where(x => x.Tzap_utc >= message.TzapUtc.ValueBegin);
}
if (message.Iik.Use)
{
query = use ? query.Where(x => x.Iik == message.Iik.Value);
}
}
I need to apply all these Where to my local collection IEnumerable< Package>
instead of collection got from DB.
Upvotes: 0
Views: 465
Reputation: 9854
queryover* has nothing to do with Linq queries. It does not involve any queryable. Thus you cannot apply any QueryOver call on a queryable. QueryOver is a strongly typed variant of nhibernate-criteria, using lambda for achieving strong typing.
If you want to use Linq with NHibernate, use linq-to-nhibernate instead.
using NHibernate.Linq;
...
var query = SessionFactory.Current.Query<Package>();
Then you would be able of substituting your query
with a queryable obtained from a in memory collection, using the Linq Enumerable.AsQueryable
method.
*: or nhibernate-queryover, synonym vote pending.
Upvotes: 1