Page 1 of 1

relations with "deleteaction == restrict, cascade, none" in code template

Posted: Sun 04 Jun 2017 12:20
by dambsst
Hello,

I am trying to find out where is the deleteaction property of the relations.

To find out if delete == cascade is ok:

Code: Select all

((EntityAssociation) relationProperty.Association).DeleteCascaded 
(thanks to another post otherwise I would have never found it, a big "no thanks" to the people in charge of the documentation).
So let say that for the relations Many-To-1 it is enough to know if we can delete the entity or not.

But to find out if a relation Many-To-0or1 is set to "Restrict" or "Cascade" or "None" I have no idea how, it is stored in the foreign key properties but how to access the foreign key from "EntityAssociation" or "EntityRelationProperty" (or anything else why not because it is not documented) is a mystery.

Would you please be so kind to share this information?

Or really do I have to try any methods like getextendedproperties() and then try to cast the object to everything until I find it by accident?

Thanks and happy sunday

Re: relations with "deleteaction == restrict, cascade, none" in code template

Posted: Tue 06 Jun 2017 14:43
by Shalex
Your ORM is Entity Framework, isn't it?
dambsst wrote:But to find out if a relation Many-To-0or1 is set to "Restrict" or "Cascade" or "None" I have no idea how, it is stored in the foreign key properties but how to access the foreign key from "EntityAssociation" or "EntityRelationProperty" (or anything else why not because it is not documented) is a mystery.
This information is available in the storage part (SSDL) of the model:

Code: Select all

    StorageRelation relation = EntityModelMapper.GetMappedStorageRelation(association);
        if (relation != null)
            // relation.DeleteAction

Re: relations with "deleteaction == restrict, cascade, none" in code template

Posted: Tue 06 Jun 2017 17:16
by dambsst
Thanks a lot!!!!

I had no idea where to find this information, so yes I will now investigate

Code: Select all

EntityModelMapper.GetMappedStorageRelation(association);
and I am sure I will find out everything I need.

Yes my ORM is entity framework, but actually I am using it to build the layers and patterns for OData too (wcf data services in C#), to be used with asp, silverlight and later UWP if it's possible I don't know yet. That's why it is important for me to prevent any wrong read/write access to the database from the remote client.

Thanks again!