Context Metadata documentation and usage

4 posts, 1 answers
  1. Kirk
    Kirk avatar
    2 posts
    Member since:
    Apr 2013

    Posted 18 Nov 2013 Link to this post

    We are importing XML data into our database & need to perform some referential integrity analysis on the data to be imported. To do so we need to make comparisons of Open Access entity navigation, key, and foreign key properties, but we are having a hard time identifying the properties using the context metadata. Specifically, we want to determine from the metadataContainer:
    1. The associations each entity is involved in
    2. The navigation properties on both ends
    3. the identity key properties for the entities on both ends
    4. the foreign key properties for the entities on both ends (for this association)

    We can find 1, 2, and 3, but are stuck determining 4. It would seem that The MetaForeignKeyAssociation.MetaDataProperties.AssociationParts would give us item 4, but the ForeignKeyMember field is always null in all our tests.
    Any ideas??

    To clarify... we can find ForeignKey Members, but can't find a link between the ForeignKeyMember and the NavigationMember (so if there are two associations, as in two addresses, like shipping and billing, we can't determine which Foreign keys apply to each...) We are trying to deal with our entities generically at design time...

  2. Answer
    Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 21 Nov 2013 Link to this post

    Hello Kirk,

    As discussed in support thread 760102, Telerik OpenAccess ORM allows you to examine the associations related to a given persistent type and to precisely determine the foreign key property a given association depends on.

    In order to achieve that, you would be using the metadata types supported by OpenAccess ORM. Additionally, the following sample workflow was suggested:
    using (EntitiesModel dbContext = new EntitiesModel())
    {
        foreach (MetaPersistentType type in dbContext.Metadata.PersistentTypes)
        {
            //Retrieves the associations in which a given type is the child type
            IEnumerable<MetaAssociation> associations = dbContext.Metadata.Associations.Where(t => t.Source.Name == type.Name);
      
            foreach (MetaAssociation association in associations)
            {
                //Retrieves a list of members that represent the foreign key properties of the class
                IList<MetaPrimitiveMember> keys = association.GetSourceConceptualKeys();
            }
        }
    }
    With it, you can filter the associations in the model and can extract the foreign key properties of a given type that participate in a given association.

    I hope you find this feasible. I am looking forward to your feedback.


    Regards,
    Doroteya
    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. Kirk
    Kirk avatar
    2 posts
    Member since:
    Apr 2013

    Posted 21 Nov 2013 Link to this post

    That worked, I was unaware of the association.GetSourceConceptualKeys()..., I'm used to using an MSDN style documentation to find functionality...searching around the OpenAccess online documentation, I never found any reference to GetSourceConceptualKeys (Search comes up with zero references)... after your reply, I've begun using the object browser for find available methods... maybe thats what Telerik always intended...

    Anyways FYI, when I use fluent mapping from the RLinq file to generate my EntityModel, the association.GetSourceConceptualKeys() returns zero keys for all entities... once I switched back to XML mapping, the keys showed up. At this point I'm ok w/ XML model mapping, so I'm good to go.
  5. Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 26 Nov 2013 Link to this post

    Hello Kirk,

    I am glad that the suggested solution was feasible to you.

    Thank you for bringing the issue with the returned result from the GetSourceConceptualKeys() method to our attention. We successfully reproduced it and at the time present, it seems that this is the designed behaviour. In the described scenario where there is an .rlinq file and the mapping type is Fluent, the OpenAccess runtime does not need additional information in order to work correctly with the association, and therefore the AssociationParts.ForeignKeyMember property is not set.

    Additionally, excuse us for the inconvenience related to the documentation of the method. Currently, it is documented only in our API Reference (the description is displayed in Visual Studio's IntelliSense too) which is distributed as an offline resource (you can download it from here). Providing an online access to it is on our roadmap and we are planning to deliver it with one of our following releases.

    Do not hesitate to get back to us in case you have other questions or if you notice anything else peculiar.


    Regards,
    Doroteya
    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!
Back to Top