Free NHibernate has a lot to many issues related to the Convention

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?
+6
conventions many-to-many fluent-nhibernate nhibernate-mapping
source share

No one has answered this question yet.

See related questions:

12
NHIbernate free auto production on List <string>?
4
The Free Nhibernate ManyToMany Collection - Not Rescue Associations
4
Free NHibernate. Auto match and legend
3
Free NHibernate Mapping of Many-to-Many Bidirectional Communications Using the Association Class
2
Free NHibernate: HasManyToMany Display By Agreement
2
Matching a List of Interface Implementations to Fluent NHibernate
2
NHibernate Free Cascading Conventions - Remote Instance Submitted for Update
one
Fluent NHibernate performs an update after inserting onto a composite key
one
NHibernate - remove many-to-many associations
0
Free Nhibernate Column Matching

All Articles