many to many relationship in model first does not create junction tables

3 posts, 1 answers
  1. Erdem
    Erdem avatar
    22 posts
    Member since:
    Sep 2013

    Posted 27 May 2014 Link to this post




    when having many to many relationships in the model, and performing an update with the schemahandler via Code ,the junction tables are not created with the schemahandler, the "update database from model" on the other hand Does create these when performing a right click on the model.

    Am I missing a setting?

    I've selected the "update schema" storage behaviour property for each table, but I can't select such a thing for the relationship it seems.



  2. Answer
    Boyan
    Admin
    Boyan avatar
    100 posts

    Posted 30 May 2014 Link to this post

    Hello Erdem,

    When using the XML mapping through the Visual Designer you need to set the ShouldUpdateSchema setting to true in order to update the database schema pragmatically based on your model. In order to do that please follow those steps:
    1. Create new class partial to you context.
    2. In this class override the OnDatabaseOpen.
    3. Set ShouldUpdateSchema​ to true for each type and join association.
    4. At this point you could use the Schema Handler to update the database schema.

    Here is an example (in the case the context class is named EntitiesModel):
    public partial class EntitiesModel
       {
           protected override void OnDatabaseOpen(Telerik.OpenAccess.BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer currentMetadataContainer, Telerik.OpenAccess.Metadata.MetadataContainer aggregatedMetadataContainer)
           {
               var persistentTypes = currentMetadataContainer.PersistentTypes;
               foreach (var type in persistentTypes)
               {
                   type.ShouldUpdateSchema = true;
                   foreach (var member in type.Members)
                   {
                       var navigationalMember = member as Telerik.OpenAccess.Metadata.MetaNavigationMember;
                       if (navigationalMember != null)
                       {
                           var joinAssociation = navigationalMember.Association as Telerik.OpenAccess.Metadata.MetaJoinTableAssociation;
                           if (joinAssociation != null)
                           {
                               joinAssociation.ShouldUpdateSchema = true;
                           }
                       }
                   }
               }
     
               base.OnDatabaseOpen(backendConfiguration, currentMetadataContainer, aggregatedMetadataContainer);
           }
       }


    Should you have any further question, do not hesitate to contact us again.

    Regards,
    Boyan
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
  4. Erdem
    Erdem avatar
    22 posts
    Member since:
    Sep 2013

    Posted 30 May 2014 in reply to Boyan Link to this post


    Thanks, It looks like this works.

    I would never have found out about this without the response...
Back to Top