Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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
C# Nhibernate子查询-无法解析类型x的属性_C#_Sql_Nhibernate_Orm_Fluent Nhibernate - Fatal编程技术网

C# Nhibernate子查询-无法解析类型x的属性

C# Nhibernate子查询-无法解析类型x的属性,c#,sql,nhibernate,orm,fluent-nhibernate,C#,Sql,Nhibernate,Orm,Fluent Nhibernate,我需要一些帮助,找出一个查询应该过滤的基础上一对多的关系。我有一个表'Product'和'ProductType'。其中“产品”有许多“产品类型”。这些模型工作得很好,我只是不知道如何根据“ProductType”记录过滤“Product”记录 在本例中,我想选择一个“产品”,其中Product.Name==“somename”&&Product.Version==“9.6”。我想在ProductType.Type==“someType”的位置筛选这些结果。 以下内容正在引发异常: 无法解析属性

我需要一些帮助,找出一个查询应该过滤的基础上一对多的关系。我有一个表'Product'和'ProductType'。其中“产品”有许多“产品类型”。这些模型工作得很好,我只是不知道如何根据“ProductType”记录过滤“Product”记录

在本例中,我想选择一个“产品”,其中Product.Name==“somename”&&Product.Version==“9.6”。我想在ProductType.Type==“someType”的位置筛选这些结果。 以下内容正在引发异常:

无法解析属性:ProductType的:my.namespace.ProductType

我使用的例子来自Ayende的博客:

var product=\u session.CreateCriteria()
.Add(Restrictions.Eq(“Name”、“somename”))
.添加(限制.Eq(“版本”,“9.6”))
.Add(子查询.PropertyIn(“Id”),
DetachedCriteria.For()
.SetProjection(Projections.Property(“Product.Id”))
.CreateCriteria(“产品类型”)
.Add(Restrictions.Eq(“Type”、“someType”))
)).List().SingleOrDefault();
我接近了吗?有人能帮我吗?谢谢

编辑

这让我很紧张。如果我删除了第二个CreateCriteria,我会得到一个填充了类型的产品。一旦我添加了连接回。。我得到0个结果

 var products = _session.CreateCriteria("Product")
                                   .Add(Restrictions.Eq("Name", "somename"))
                                   .Add(Restrictions.Eq("Version", "9.6")) //This works
                                   .CreateCriteria("Types", "productTypes",   JoinType.LeftOuterJoin)
                                   .Add(Restrictions.Eq("Type", "typename")).List<Product>();

            return products.FirstOrDefault();
var products=\u session.CreateCriteria(“产品”)
.Add(Restrictions.Eq(“Name”、“somename”))
.Add(Restrictions.Eq(“Version”,“9.6”)//这很有效
.CreateCriteria(“类型”、“产品类型”、JoinType.LeftOuterJoin)
.Add(Restrictions.Eq(“Type”、“typename”)).List();
退货产品。FirstOrDefault();

非常接近-您只需要告诉CreateCriteria如何进入ProductType。例如:

var product = _session.CreateCriteria<Product>()
    .Add(Restrictions.Eq("Name", "somename"))
    .Add(Restrictions.Eq("Version", "9.6"))
    .Add(Subqueries.PropertyIn("Id",
         DetachedCriteria.For<ProductType>()
        .SetProjection(Projections.Property("Product.Id"))
        .CreateCriteria("Product.ProductType", JoinType.InnerJoin)
        .Add(Restrictions.Eq("Type", "someType"))
     ))
     .List<Product>()
     .SingleOrDefault();
var product=\u session.CreateCriteria()
.Add(Restrictions.Eq(“Name”、“somename”))
.添加(限制.Eq(“版本”,“9.6”))
.Add(子查询.PropertyIn(“Id”),
DetachedCriteria.For()
.SetProjection(Projections.Property(“Product.Id”))
.CreateCriteria(“Product.ProductType”,JoinType.InnerJoin)
.Add(Restrictions.Eq(“Type”、“someType”))
))
.List()
.SingleOrDefault();

真奇怪,我也遇到了同样的问题。事实上。。现在它抱怨无法解析属性:{namespace}的Product.Id。您能用Product和ProductType类以及您使用的映射更新这个问题吗?
var product = _session.CreateCriteria<Product>()
    .Add(Restrictions.Eq("Name", "somename"))
    .Add(Restrictions.Eq("Version", "9.6"))
    .Add(Subqueries.PropertyIn("Id",
         DetachedCriteria.For<ProductType>()
        .SetProjection(Projections.Property("Product.Id"))
        .CreateCriteria("Product.ProductType", JoinType.InnerJoin)
        .Add(Restrictions.Eq("Type", "someType"))
     ))
     .List<Product>()
     .SingleOrDefault();