开发者

Nhibernate.linq Session.Query ignore not.lazyload

开发者 https://www.devze.com 2023-03-15 22:15 出处:网络
I\'m using SharpArch, i extended the Repository adding this methods : public IQueryable<T> FindAll(Expression<Func<T, bool>> expression)

I'm using SharpArch, i extended the Repository adding this methods :

    public IQueryable<T> FindAll(Expression<Func<T, bool>> expression)
{
  var queryable = Session.Query<T>();
  return queryable.Where(expression);
}

 public IQueryable<T> FindAll(ISpecification<T> specification)
{
  var queryable = Session.Query<T>();
  return specification.SatisfyingElementsFrom(queryable);
}

Now i can use lambda expressions and specifications with nibernate.linq:

 var printers = repository.FindAll(x => x.IpAddress != null).ToList();

My problem is that it ignore the Not.Lazyload of my entity map.

instead if i use the FindAll with Dictionary provided by sharpArc it work开发者_如何转开发s correctly without lazy load.

Using reflection this is what they do:

 public virtual IList<T> FindAll(IDictionary<string, object> propertyValuePairs)
{
  Check.Require((propertyValuePairs != null) && (propertyValuePairs.Count > 0), "propertyValuePairs was null or empty; it has to have at least one property/value pair in it");
  ICriteria criteria = this.Session.CreateCriteria(typeof(T));
  foreach (string str in propertyValuePairs.Keys)
  {
    if (propertyValuePairs[str] != null)
    {
      criteria.Add(Restrictions.Eq(str, propertyValuePairs[str]));
    }
    else
    {
      criteria.Add(Restrictions.IsNull(str));
    }
  }
  return criteria.List<T>();
}

Thank you


You may want to try using Session.QueryOver<> instead of Session.Query<>. I will try and dig up the posting that I read a while back but if I remember correctly Query does not respect all the instructions in the mappings ?yet?.

I'll post more here if I find the relevant article... hope this helps in the mean time.


Your question is really confusing, but you may want to look into the Fetch() method, assuming you still need help with this.

I am also posting this just in case others come to this question.

Here is a really great article on Eager fetching with NHibernate.Linq. I am not sure if this is a problem with your mappings though.

0

精彩评论

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

关注公众号