Correcting Many to Many Relationships with the Domain Model

Thread is closed for posting
2 posts, 0 answers
  1. Jason
    Jason avatar
    5 posts
    Member since:
    Aug 2010

    Posted 10 Feb 2011 Link to this post

    I have several many to many tables that OpenAccess did not recognize as such because they have a rowguid column that SqlServer added for replication purposes.

    I've gone through the models in the Schema explorer and changed the incorrect table's IsJoinTable property to True.

    But what now?  Can I force a regeneration of the .cs files?  

    All of the examples I've seen have been for the older version of OpenAccess.

    Any help or links would be appreciated.

    [A few hours later]
    Here's a specific example of three tables that work.  I've got Owner, PhoneNumber and OwnerPhoneNumber (OwnerPhoneNumber did not have the rowguild column so OpenAccess recognized it as a Many-Many table).

    OwnerPhoneNumber shows up as a Many-Many table in the Model Schema Explorer.  When I pull up Owners in the Mapping Details Editor I see in the Relationships that:
    Relates to: PhoneNumber (PhoneNumbers -> Owners)           [x] Use join table: OwnerPhoneNumber
    Relationship Ends                                 Join Table Ends
    Owner Table                                         OwnerPhoneNumber Table
         OwnerId:int                                           OwnerId:int
    PhoneNumber Table                                   
         PhoneNumberId:int                              PhoneNumberId:int
    (sorry for the adhoc 'screenshot')

    Now for one that doesn't work.  I have the Facility table, PhoneNumber and FacilityPhoneNumber

    When I look at the relations in the Mapping Details Editor for Facility the only 'Relates To' drop down I have is for FacilityPhoneNumber. (FacilityPhoneNumbers -> Facility) 

    I'm a bit closer, I think.  I deleted the relationships between Facility, PhoneNumber and FacilityPhoneNumber.  Made sure that FacilityPhoneNumber is set to IsJoinTable and created an association between Facility and PhoneNumber.  The new relationship uses the FacilityPhoneNumber join table.  My only problem is that I don't see this relationship in the .CS file.  Here's what got generated for the Facility table:
    private IList<PhoneNumber> phoneNumbers = new List<PhoneNumbers>();
    [Collection(InverseProperty = "Facility", IsManaged = true)]

    How do I get generated code that looks like:

    private IList<PhoneNumber> phoneNumbers = new List<PhoneNumber>();
    [JoinTableAssociation(TableName = "OwnerPhoneNumber", OwnerColumns = "OwnerId", TargetColumns = "PhoneNumberId")]
    [Column("OwnerId", OpenAccessType = OpenAccessType.Int32, IsPrimaryKey = true, SqlType = "int")]
    [Column("PhoneNumberId", OpenAccessType = OpenAccessType.Int32, IsPrimaryKey = true, SqlType = "int")]



  2. Alexander
    Alexander avatar
    727 posts

    Posted 16 Feb 2011 Link to this post

    Hello Jason,

    Please note that in case of m:n relations, the join table is used internally and it is required that it is not mapped to a class. Having this in mind, to setup the second association you need to follow these steps:
    • Make sure the FacilityPhoneNumber table is not mapped to a class. If it is, delete the class from the diagram.
    • Set the IsJoinTable property of the FacilityPhoneNumber table to True. 
    • Drag an Association from the Toolbox from the Facility class to PhoneNumber. In the pop-up dialog enable the Use Join Table combobox and select the FacilityPhoneNumber table from the drop down.
      Then configure the mappings between the join table and the main tables.
    I hope that helps. If you continue to experience problems, please let me know.
    Best wishes,
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Back to Top