CreateUpdateDDLScript() drop some constraints

Thread is closed for posting
3 posts, 0 answers
  1. Lagrange
    Lagrange avatar
    17 posts
    Member since:
    Sep 2010

    Posted 20 Jun 2015 Link to this post


    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 :
    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. Lagrange
    Lagrange avatar
    17 posts
    Member since:
    Sep 2010

    Posted 20 Jun 2015 in reply to Lagrange Link to this post

    I have a sample app demonstrating the 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 !

  3. Boyan
    Boyan avatar
    100 posts

    Posted 24 Jun 2015 Link to this post

    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.

    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top