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

CreateUpdateDDLScript() drop some constraints

2 Answers 18 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Lagrange
Top achievements
Rank 1
Lagrange asked on 20 Jun 2015, 03:34 PM

Hi,

I've an issue with the self updating feature of openaccess.

The CreateUpdateDDLScript() always drop 5 constraints in my database, and I don't understand why (and why not all others...)

 

When I "update schema from database" through the rlinq designer, theses constraints are well recognised. And when I "update database from schema" through the rlinq designer, theses constraints are not dropped. So I don't understand why they are dropped at runtime.

I've used this code to see what's append at runtime : http://www.telerik.com/forums/createupdateddlscript-not-generate-constraints-and-foregein-keys
it look like in the MetaPersistentType of theses tables, the Table.Constraints collection is empty.

I've checked that in the .rlinq model, the constraints are well defined, and they are : both in the navigation property, and in the referenced table, and all theses tables are referenced in the endpointTypesString field of the ".tt" file.

 

For now I've disabled the feature, as we are still in development, and not in production, but I will need it back in some weeks for the quality tests.

Thanks for your help !

2 Answers, 1 is accepted

Sort by
0
Lagrange
Top achievements
Rank 1
answered on 20 Jun 2015, 03:59 PM

I have a sample app demonstrating the issue...in this one, only one constraint is dropped, while a bunch of index is created... again only at runtime. All is well in designer, and after the contraints are dropped in runtime, they are well recreated at design time...

I don't find how to attach this in the forum, so tell me and I will send you.

Thanks !

0
Boyan
Telerik team
answered on 24 Jun 2015, 02:40 PM
Hi Lagrange,

In order to make schema updates programmatically using xml mapping with a .rlinq file you should take the following steps in order to assure that all association are correctly pushed to the database:

1. Please make sure that the NullForeignKey setting is set to true. This should assure that constraints are going to be placed. Please refer to this documentation article for further information on the matter.
2. Please make sure that ShouldUpdateSchema is set to true for every type, association and join table within your model. This could be done by extending a Telerik Data Access context a partial class providing an override for the OnDatabaseOpen as shown below: 

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);
   }
}

3. Use the schema handler to create and execute the respective database script as shown in this documentation article

Please let us know if this resolve the issue on your side.

Do not hesitate to get back to us with any further questions.


Regards,
Boyan
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Development (API, general questions)
Asked by
Lagrange
Top achievements
Rank 1
Answers by
Lagrange
Top achievements
Rank 1
Boyan
Telerik team
Share this question
or