Fluent NHibernate DuplicateMappingException with AutoMapping

后端 未结 6 1766
终归单人心
终归单人心 2021-01-03 06:08

Summary:

I want to save two classes of the same name and different namespaces with the Fluent NHibernate Automapper

Context

6条回答
  •  一向
    一向 (楼主)
    2021-01-03 06:46

    solution from fluent-nhibernate forums by James Gregory

    Got around to having a proper look at this tonight. Basically, it is down to the AutoImport stuff the exception mentioned; when NHibernate is given the first mapping it sees that the entity is named with the full assembly qualified name and creates an import for the short name (being helpful!), and then when you add the second one it then complains that this import is now going to conflict. So the solution is to turn off the auto importing; unfortunately, we don't have a way to do that in the RC... I've just commited a fix that adds in the ability to change this in a convention. So if you get the latest binaries or source, you should be able to change your Conventions line in your attached project to do this:

    .Conventions.Setup(x =>  {   
      x.AddFromAssemblyOf();   
      x.Add(AutoImport.Never());  }); 
    

    Which adds all the conventions you've defined in your assembly, then uses one of the helper conventions to turn off auto importing.

提交回复
热议问题