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?
Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.
Entity framework requires additional connections to handle databases other than MSSQL, which nHibernate provides. In terms of data loading, SQL generation, custom column types, custom collections, and so on, NHibernate can be modified. However, the entity framework has limited extension points.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With