tags:

views:

21

answers:

1

I have the following method. This works fine if i remove the following line

.Add(Restrictions.Eq("Product.IsPopItem", true))

The error message is

could not resolve property: Product.IsPopItem of: EStore.Domain.Model.ProductCategory

I'm confident the "Product.IsPopItem" is mapped correctly as i can call this property. Do i need to add a few criteria.

 public ICollection<ProductCategory> FindByCompanyIdAndCategoryIdAndIsPop(int companyId, int id)
    {
        var products = _session
            .CreateCriteria(typeof(ProductCategory))
            .Add(Restrictions.Eq("CompanyId", companyId))
            .Add(Restrictions.Eq("CategoryId", id))
            .Add(Restrictions.Eq("Product.IsPopItem", true))
            .List<ProductCategory>();
        return products;
    }
+3  A: 

Yes you need to add an .CreateAleas

 .CreateAlias("Product", "product", JoinType.InnerJoin)

please change JoinType to your need, and use "product" alias instead of property name "Product"

so final should be something like:

.CreateCriteria(typeof(ProductCategory))
        .CreateAlias("Product", "product", JoinType.InnerJoin)
        .Add(Restrictions.Eq("CompanyId", companyId))
        .Add(Restrictions.Eq("CategoryId", id))
        .Add(Restrictions.Eq("product.IsPopItem", true))
        .List<ProductCategory>());
        return products;
isuruceanu
beat me to it just as I started to type :)
Colin G
:) sorry, just helped a colleague with the same problem
isuruceanu
great, very cool.
frosty