There is no possibility to set an association to the entity in another model/assembly in the way you have described.
Try to implement the following approach of creating, for example, many-to-many association (SomeClass is a class in another model/assembly, OurClass is a class in current model/assembly; you can get samples of different types of associations mappings by creating them in the designer for classes from the same model):
1. Create the OurClass in the new Devart NHibernate Model. Set at least its primary key (e.g., OurClass_ID) property.
2. Set template's Generate Partial Class property to True so that our manual code will not be overwritten by the designer.
3. Save and generate model's code (*.cs) and mapping (*.xml) files.
4. Open the DataModel1.OurClass.cs file with a text editor and add to it:
Code: Select all
private Iesi.Collections.ISet _SomeClasses;
public virtual Iesi.Collections.ISet SomeClasses
{
get
{
return this._SomeClasses;
}
set
{
this._SomeClasses = value;
}
}
5. Open the DataModel1.OurClass.hbm.xml file with a text editor and add to it:
Code: Select all
...
<class name="OurClass" ...>
...
<set name="SomeClasses" table="OurClasses_SomeClasses" inverse="true" generic="false">
<key>
<column name="OurClass_ID" />
</key>
<many-to-many class="NamespaceOfSomeClass.SomeClass, AssemblyOfSomeClass" fetch="join">
<column name="SomeClass_ID" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
6. Now the DataModel1.OurClass.cs will not be overwritten, but this problem can happen with DataModel1.OurClass.hbm.xml. As a workaround, rename this file (e.g. to DataModel1.OurClassEditedManually.hbm.xml) via file system manager and readd it to the project with Build Action=Embedded Resource - it will not be changed by the designer but mapping will be used from here. After this, disable a standard DataModel1.OurClass.hbm.xml which will be regenerated by Entity Developer after every Run Custom Tool (when model is changed): remove DataModel1.OurClass.hbm.xml and set template's Xml Mapping Action property to DoNotGenerateMappingFiles. Be aware this approach will disable generation of mapping files for all classes in your current model. Possible solutions:
- write manually *.cs and *.xml files for your OurClass separately (not in scope of the model)
- edit standard NHibernate (or other one which you use) template to implement an additional property which can disable generation of mapping files only for a particular class.