.net – Fluent NHibernate mapping

fluent-nhibernatenet

I'm new to NHibernate and Fluent NHibernate.

Assuming I have a situation like the following

Table Activities (uniquidentier ID, varchar ActivityName)
Table ActivityParameters(uniqueidentifier ID, varchar ParameterName,
 varbinary(8000) ParameterValue)

and the following class

public static Acivity
{
     .......
     public virtual Guid Id {get; private set;}      
     public virtual string ActivityName {get; private set;}
     public virtual IDictionary<string, object> ActivityParameters {get; private set;}
}

how can i write the classmap? More specifically, how can i write the mapping for activityparameters?

Best Answer

A colleague pointed e to this site.

Based on that discussion, I've come to

Table("Activities");
        Id(x => x.Id).Column("ID").GeneratedBy.Guid();
        Map(x => x.ActivityName).Not.Nullable().Length(50);
        HasMany(x => x.ActivityParameters)
            .KeyColumn("ActivityID")
            .AsMap<string>(idx => idx.Column("ParameterName"), elem => elem.Column("ParameterValue"))
            .Not.LazyLoad()
            .ForeignKeyCascadeOnDelete()
            .Table("ActivityParameters");

I have to test this.

Related Topic