Search code examples
nhibernatemappings

Convert Mapping from XML to Confirmst(Code Mappings)


Hello I am presently converting the xml mappings to code mappings and I am stuck at one place as I am not getting the proper way to convert ManyToOne Mappings.

The XML Mappings are

 </many-to-one>
    <many-to-one class="MyProject.Activity.Communication, MyProject.Activity" name="Comm">
  <column name="CommID" />
</many-to-one>

Now I have this MyProject.Activity.Communication in other solution and don't have any reference in my mapping project. I want to specify class in my code mappings.

ManyToOne(x => x.Comm, map =>
        {
            map.Column("CommID");
        });

How do I specify class in this mapping as the Entity name is referenced so I need to add the class in my code mappings.


Solution

  • The mappings would be using Reflection to fetch the assembly name.

    ManyToOne(x => x.Survey, map =>
        {
            map.Column("SurveyID");
            map.Class(Type.GetType("MyProject.Activity.Communication, MyProject.Activity"));
        });