开发者

Nesting Linq query with NHibernate

When I try to run this piece of logic, NHibernate comes back with an error stating it has no reference to "Site".

IQueryable<Product> query = this.RetrieveAll();    
query = query.Where(x => x.Status == Product.Statuses.Approved || x.SiteProduct.Where(y => y.Site.ID == siteID).Count() > 0);

A little background. Product has a One to Many Map to SiteProduct SiteProduct has a One to Many Map to Site

Even a simpler version has issues it states it has no reference to ID:

IQueryable<Product> query = this.RetrieveAll();    
query = query.Where(x => x.Status == Product.Statuses.Approved || x.SiteProduct.Where(y => y.ID > 0).Count() > 0);

Does NHibernate have issues with nesting "Where" statements within itself?

As for the table mappings, they appear to be correct since I can transverse all the way down and capture individual records at the bottom through lazy loading. Addition, Getting and Deleting records all works开发者_JAVA技巧 perfectly. I am just having problems with nesting my Linq query.


This would have been a lot easier if someone had an answer for me on this.

What I found out through trial and error...

Apparently through lazy loading it was not going back and loading the related tables I was referencing. This was causing a null error and giving me no reference to "Site" error.

When I changed the loading from lazy loading to eager loading, there error went away.

So the moral to this story is that if the reference to a table where you are trying to use your nested where statement is null, you will get this error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜