Hi,

I have the class:
    public enum PropertyType {
        Apartment, Townhouse, AndSoOn
    }

    public class Company  {
        private readonly Iesi.Collections.Generic.ISet<PropertyType>
desiredPropertyTypes;

        public virtual Iesi.Collections.Generic.ISet<PropertyType>
DesiredPropertyTypes {
            get { return desiredPropertyTypes; }
        }

        // other stuff...
    }


and the related FNH mapping:

    HasMany<GenericEnumMapper<PropertyType>>(x =>
x.DesiredPropertyTypes)
        .AsSet().Cascade.All()
        .Access.ReadOnlyPropertyThroughCamelCaseField()
        .Element("PropertyType")
        .ForeignKeyConstraintName("FK_SaleAgentCompanyPreference_PropertyTypes")
        .KeyColumn("CompanyId")
        .Table("SaleAgentCompanyPreference_PropertyTypes");


Having that, I need to "Find all companies for the selected property
types".

So having an array of `selectedTypes`, how would I query the enum
collection (`DesiredPropertyTypes`) of the Company to check if it
contains elements from the `selectedTypes`?

The Criteria API is needed as there is a whole bunch of other
parameters built dynamically.

Tried to use restriction and variations, but it gives me
"NHibernate.QueryException : could not resolve property: dpt of:
Model.Company"

var selectedTypes = new[] { PropertyType.Appartment,
PropertyType.Townhouse};
var allFound = session.CreateCriteria<Company>("a")
    .CreateAlias("a.DesiredPropertyTypes", "dpt",
JoinType.LeftOuterJoin)
    .Add(
        Restrictions.InG("dpt", selectedTypes)
     ).ToList<Company>();


Thanks in advance,
Dmitriy.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to