I am new to nhibernate and nhibernate free. I want to write a free nhibernate auto-parsing agreement to handle the creation of many, many mappings for my objects.
Here is what I have right now:
using System; using FluentNHibernate.Conventions; using FluentNHibernate.Mapping; namespace Namespace { public class HasManyToManyConvention : IHasManyToManyConvention { public bool Accept(IManyToManyPart target) { return true; } public void Apply(IManyToManyPart target) { var parentName = target.EntityType.Name; var childName = target.ChildType.Name; const string tableNameFmt = "{0}To{1}"; const string keyColumnFmt = "{0}Fk"; string tableName; if (parentName.CompareTo(childName) < 0) { tableName = String.Format(tableNameFmt, parentName, childName); } else { tableName = String.Format(tableNameFmt, childName, parentName); } target.WithChildKeyColumn(String.Format(keyColumnFmt, childName)); target.WithParentKeyColumn(String.Format(keyColumnFmt, parentName)); target.WithTableName(tableName); target.Cascade.All(); } } }
This seems to work, but I believe there is a better way to do this.
Now my questions are:
- Do you have a better way to do this?
- Do you usually require Cascade behavior?
- Do I need to worry about anything other than the fact that both sides of this association have the same table name?
conventions many-to-many fluent-nhibernate nhibernate-mapping
kuhlmancer
source share