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

Classic Api - MetaDataContainer Constraints

9 Answers 50 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.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 08 Jan 2014, 07:23 AM
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..)

9 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 13 Jan 2014, 10:48 AM
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!
0
Wolfgang
Top achievements
Rank 1
answered on 14 Jan 2014, 07:49 AM
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
0
Accepted
Ady
Telerik team
answered on 16 Jan 2014, 04:40 PM
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!
0
Wolfgang
Top achievements
Rank 1
answered on 23 Jan 2014, 12:37 PM
Hi Ady,

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

Thank you.
Wolfgang
0
Ady
Telerik team
answered on 27 Jan 2014, 03:59 PM
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!
0
Wolfgang
Top achievements
Rank 1
answered on 22 Jul 2014, 12:26 PM
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.

0
Ady
Telerik team
answered on 24 Jul 2014, 12:12 PM
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.
 
0
Wolfgang
Top achievements
Rank 1
answered on 07 Aug 2014, 02:45 PM
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.
0
Accepted
Ady
Telerik team
answered on 12 Aug 2014, 11:54 AM
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.
 
Tags
Development (API, general questions)
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Ady
Telerik team
Wolfgang
Top achievements
Rank 1
Share this question
or