Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent nhibernate Nhibernate.linq Session.Query ignore not.lazyload_Fluent Nhibernate_Linq To Nhibernate_Sharp Architecture - Fatal编程技术网

Fluent nhibernate Nhibernate.linq Session.Query ignore not.lazyload

Fluent nhibernate Nhibernate.linq Session.Query ignore not.lazyload,fluent-nhibernate,linq-to-nhibernate,sharp-architecture,Fluent Nhibernate,Linq To Nhibernate,Sharp Architecture,我使用的是SharpArch,我扩展了存储库,添加了以下方法: public IQueryable<T> FindAll(Expression<Func<T, bool>> expression) { var queryable = Session.Query<T>(); return queryable.Where(expression); } public IQueryable<T> FindAll(ISpeci

我使用的是SharpArch,我扩展了存储库,添加了以下方法:

    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);
}
我的问题是它忽略了实体映射的Not.Lazyload

相反,如果我使用sharpArc提供的FindAll with Dictionary,它可以在没有延迟加载的情况下正常工作

使用反射这就是他们所做的:

 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>();
}
公共虚拟IList FindAll(IDictionary PropertyValue对)
{
检查.Require((propertyValuePairs!=null)&&(propertyValuePairs.Count>0),“propertyValuePairs为null或空;其中必须至少有一个属性/值对”);
ICriteria-criteria=this.Session.CreateCriteria(typeof(T));
foreach(propertyValuePairs.Keys中的字符串str)
{
if(propertyValuePairs[str]!=null)
{
标准.Add(Restrictions.Eq(str,propertyValuePairs[str]));
}
其他的
{
标准.Add(Restrictions.IsNull(str));
}
}
返回条件。List();
}

谢谢

您可能想尝试使用Session.QueryOver而不是Session.Query。我会尝试挖掘我之前读过的帖子,但如果我没记错的话,Query并没有遵守映射中的所有说明?还没有


如果我找到相关文章,我会在这里发布更多。。。同时希望这对您有所帮助。

您的问题确实让人困惑,但您可能需要研究Fetch()方法,前提是您仍然需要这方面的帮助

我也张贴这篇文章,以防万一其他人会问这个问题


下面是关于NHibernate.Linq的急切抓取。不过,我不确定这是否是您的映射的问题。

对于QueryOver,我无法使用规范……我错了吗?Session.Query与spec和Linq完美配合,我只是没有懒散的负载问题……也许我可以使用HQL,但我编写了复杂的Linq查询,所以我喜欢使用规范模式并对规范进行一些单元测试,而不需要进行集成测试。我可以使用Hql或Ado.Net解决我的问题,但我想知道我是否可以解决这个问题。
 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>();
}