Amira Elsayed Ismail
Amira Elsayed Ismail

Reputation: 9394

Inheritance in nHibernate

I have the following entities

public abstract class ProductAttribute
{
    public virtual long Id { get; private set; }
    public virtual string Name { get; set; }
}

public class TextAttribute : ProductAttribute
{
   public virtual string Value { get; set; }
}

and 

public class Product
{        
    public virtual long Id { get; private set; }
    public virtual IList<ProductAttribute> Attributes { get; private set; }
}

what I want to do now is to get the product that has TextAttribute with value = myValue

Any help will be appreciated

Thanks in Advance

Upvotes: 0

Views: 127

Answers (1)

rebelliard
rebelliard

Reputation: 9611

Just like your other question was answered:

var foobar = "foobar";
var result = Session.Linq<Product>()
                    .Where(product => product.Attributes
                                             .Any(attr => attr.Value == foobar))
                    .List<Product>();

Upvotes: 1

Related Questions