开发者

FluentNHibernate acts differently on different machines

开发者 https://www.devze.com 2022-12-22 04:04 出处:网络
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 doe

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开发者_Python百科.

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?


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.


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);
    }
  }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号