This is a migrated thread and some comments may be shown as answers.

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

2 Answers 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Erdem
Top achievements
Rank 1
Erdem asked on 27 May 2014, 06:44 PM



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 Answers, 1 is accepted

Sort by
0
Accepted
Boyan
Telerik team
answered on 30 May 2014, 12:12 PM
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.
 
0
Erdem
Top achievements
Rank 1
answered on 30 May 2014, 05:51 PM

Thanks, It looks like this works.

I would never have found out about this without the response...
Tags
General Discussions
Asked by
Erdem
Top achievements
Rank 1
Answers by
Boyan
Telerik team
Erdem
Top achievements
Rank 1
Share this question
or