Evg
Evg

Reputation: 98

NHibernate AsQueryable LINQ analogue

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

Answers (1)

Fr&#233;d&#233;ric
Fr&#233;d&#233;ric

Reputation: 9854

* 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 , using lambda for achieving strong typing.

If you want to use Linq with NHibernate, use 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 , synonym vote pending.

Upvotes: 1

Related Questions