Classic Api - MetaDataContainer Constraints

10 posts, 2 answers
  1. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 08 Jan 2014 Link to this post

    Hello,

    I try to get the links between objects from an objectscope.

    At the moment i use a loop over all MetaPersistentTypes ( foreach (MetaPersistentType metaType in this.objectscope.DataBase.MetaData) )
    to get Table.Name and FullName and additional loop through constraints to get the links between objects
    (foreach (MetaConstraint constraint in this.objectscope.DataBase.MetaData.Constraints) ).


    For some casses it seems that not all information are available.

    [Serializable]
    [Persistent(IdentityField = "rowId")]
    public class DNO
    {
         ...
        private O or:
        private T tof;
     
        [FieldAlias("tof")]
        public T Tof
        {
            ... getter / setter
        }
     
        [FieldAlias("or")]
        public O Or
        {
            ... getter / setter
        }
    }
    in the Constraints I find only a link DNO -> Tof, not DNO -> O
    looking at the App.config, I find the following information:
    <class name="DNO">
       ...
       <field name="or">
           <extension key="db-ref" value="rowId">
               <extension key="db-column">
                   <extension key="db-column-name" value="RowId_Or" />
                </extension>
           </extension>
       </field>
       <field name="tof">
           <extension key="db-ref" value="rowId">
               <extension key="db-column">
                   <extension key="db-column-name" value="RowId_Tof" />
               </extension>
           </extension>
       </field>
    Which looks for me structural equal (what i don't know is what is the db-ref line for? In some parts there seem to be foreign keys with the db-ref, in other parts not). So why is the one link a constraint, and the other one isn't? (In the "Forward Mapping Dialog" (very slow and often stalling) both have a mark that constraints should be created, however i do not see in which file this information is saved) Is there a way to get the Or contraint from MetaData? Best regards, Wolfgang Oh forgot something: Is it possible to get the Column name of a property from a MetaForeignKeyAssociation?
    I first tried it with getting the association,then 
    IList<MetaPrimitiveMember> keys = association.GetSourceConceptualKeys();
    
    This returns null.
    If I look in VS in the variable, I can see that there is something like association.AssociationParts[0].ForeignKeyColumn whihc seems to have the information, but is not accessable (AssociationParts is private and i have no clue hoq to get the [0] value..)
  2. Ady
    Admin
    Ady avatar
    589 posts

    Posted 13 Jan 2014 Link to this post

    Hello Wolfgang,

     I assume that your model is Forward mapped. Before I attempt to answer your questions regarding how to obtain the metadata, I would like to know what is it that you are trying to achieve so that I could propose a better solution.

    Regarding your questions
    1. Ideally you should be able to obtain all constraints in the 'Constraints' collection of the MetadataContainer. If you obtain the DDL script using SchemaHandler.CreateDDLScript is the constraint for the field 'Or' present in the script?
    2. Each 'field' node in the mapping has further entries for it's column mapping. If the field is a reference field then this is represented using a db-ref node. db-ref node is required if the field uses a composite Foreign key, If it is a single column FK then the db-ref is optional. It will work with out without the db-ref node.
    3. You can use the MetaForeignKeyAssociation.GetTargetRelationalKeys() method to get a list of columns that make up the foreign key of an association.
     Hope this answers your questions. To get back in case you need further assistance.

    Regards,
    Ady
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  3. DevCraft banner
  4. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 14 Jan 2014 Link to this post

    Hi Ady

    we try to achieve a speedup on deletion of bulk data through usage of SQL statements (We keep track of changes for undo, then do a bulk delete at specified points).
    We have seen that at program end we could rather let Telerik delete Data (and it took up to a few minutes with a lot of data with constraints) or we used the metamodel, a bit recursion and delete per sql. 
    In the SQL case we were a lot faster then in the telerik delete case.
    If we exchange the usage of the Metamodel by using some reflection we find additional data which should be deleted.
    The reflection and recursion parts is only to be flexible, but as it is cached the total impact for the runtime is not huge.

    1. No, I only find the one for 'Tof' (ALTER TABLE "DNO" ADD CONSTRAINT "ref_DNO_Tof" FOREIGN KEY ("RowId_Tof") REFERENCES "Tof"("RowId")), not the one for 'Or'

    2. The project does not have composite primary keys ( design decision )

    Regards
    Wolfgang
  5. Answer
    Ady
    Admin
    Ady avatar
    589 posts

    Posted 16 Jan 2014 Link to this post

    Hello Wolfgang,

     One use case where we do not create a constraint for a reference is if a circular reference is detected.Is that the case?
    Can you send me your model with the mapping? I could have a closer look to see why the constraint is missing.

    Regards,
    Ady
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  6. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 23 Jan 2014 Link to this post

    Hi Ady,

    yes that is the case. (And after clarification: the circular references are used to get the opposite site fast ... )

    Thank you.
    Wolfgang
  7. Ady
    Admin
    Ady avatar
    589 posts

    Posted 27 Jan 2014 Link to this post

    Hi Wolfgang,
     
     Do you need further assistance on this issue? If no, maybe you could close this ticket.

    Regards,
    Ady
    Telerik
    OpenAccess ORM Q3 2013 simplifies your model operations even further providing you with greater flexibility. Check out the list of new features shipped with our latest release!
  8. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 22 Jul 2014 in reply to Ady Link to this post

    Further help would be okay, but I really don't know where to start.

    The problem came up again after half a year n.

    If we let data access or sql delete data there will be cases where an first element is deleted which would be referenced by another one.(where the constraint is missing)

     If the other element is then accessed data access will fire an error because the element to which the first element links is not available.

  9. Ady
    Admin
    Ady avatar
    589 posts

    Posted 24 Jul 2014 Link to this post

    Hello Wolfgang,

     Can you not set the referencing column to 'null' before you delete the items in the referenced table?
    The problem seems to be more related to your database design. If you can provide more information on the problem you are trying to solve and the database design I could try and help you.

    Regards,
    Ady
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  10. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 07 Aug 2014 in reply to Ady Link to this post

    I cannot set to null.

    lets assume the following 
    if (this.someField!= null && !objectScope.IsRemoved(this.someField))
      this.PropertyForSomeField = null;

    If i try to fiend out wether the thing is removed i think i need to know that it is not null.
    If i try to find out wether it is null i already get an exception that is cannot be read or written to an disposed object.
  11. Answer
    Ady
    Admin
    Ady avatar
    589 posts

    Posted 12 Aug 2014 Link to this post

    Hello Wolfgang,

     You can specify a setting in the app.config file that treats dangling references as null. Please specify the following in the 'backendconfiguration' node in the app.config

    <versant.nullify.broken.refs>true</versant.nullify.broken.refs>

    If you now try to access a foreign key value with no row in the referenced table you will get back a null. 

    Do get back in case you need further assistance.

    Regards,
    Ady
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top
DevCraft banner