Association to Other Model

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Posts: 5
Joined: Mon 14 May 2012 05:04

Association to Other Model

Post by alireza_eslampanah » Mon 28 May 2012 06:16

I Want to Create An Association to the Entity That Is Not in Current Model(it is in Other Model In Other Assembly ).
If It Would Be Like Type Property In The Model That I Can Direct Type Name In A textBox;
That In the Association Dialog,Instead Of Just Combo , There is a textBox that I Write Type Name ,Will Solve My Problem

Thanks For Your Attention
Sorry For My Bad English

Devart Team
Posts: 7976
Joined: Thu 14 Aug 2008 12:44

Re: Association to Other Model

Post by Shalex » Tue 29 May 2012 12:55

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
                return this._SomeClasses;
                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">
        <column name="OurClass_ID" />
      <many-to-many class="NamespaceOfSomeClass.SomeClass, AssemblyOfSomeClass" fetch="join">
        <column name="SomeClass_ID" />
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.

Post Reply