views:

40

answers:

3

I have run into an issues with FluentNHibernate that i hope someone can help me with.

I have a many-to-many relationship between two classes named CampaignAreas and CampaignProducts. Sadly Fluent doesn't map the relation-table to the same table name on my machine as it does on my colleagues. It is named CampaignProductsToCampaignAreas and CampaignAreasToCampaignProducts respectivly.

We have the exact same version of the code, the same dll'es for NH, fluent etc. and we have been rebuilding and resetting IIS several times, so its not any of that basic stuff.

Any ideas how to fix this?

A: 

I don't know Fluent, but you should be able to specify the table name of the many-to-many relation. This would be cleaner anyway.

Stefan Steinegger
Problem is i am trying to avoid writing the map myself. The automapping does work, so it shouldent be a problem besides that it changes the name on one machine.
Christian Nielsen
+1  A: 

I use this convention to name a many-to-many table with AutoMapping

  public class CustomManyToManyTableNameConvention : ManyToManyTableNameConvention
  {
    protected override string GetBiDirectionalTableName(IManyToManyCollectionInspector collection, IManyToManyCollectionInspector otherSide)
    {
      return String.Format("{1}{0}", collection.EntityType.Name, otherSide.EntityType.Name);
    }

    protected override string GetUniDirectionalTableName(IManyToManyCollectionInspector collection)
    {
      return String.Format("{1}{0}", collection.EntityType.Name, collection.ChildType.Name);
    }
  }
Maggie
+2  A: 

Depending on the version of Fluent NHibernate you're using, there were some race-conditions with naming tables in a bi-directional many-to-many relationship; FNH used to pick whichever side of the relationship it found first, and for whatever reason .Net would give them in a different order (we just call Assembly.GetTypes()).

Anyway, I digress. Try upgrading to the latest version of FNH, and I'd also suggest you follow Maggie's suggestion and use a convention to control table naming.

James Gregory

related questions