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

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
dambsst
Posts: 6
Joined: Sun 29 Jan 2017 15:10

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

Post by dambsst » Sun 04 Jun 2017 12:20

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Tue 06 Jun 2017 14:43

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

dambsst
Posts: 6
Joined: Sun 29 Jan 2017 15:10

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

Post by dambsst » Tue 06 Jun 2017 17:16

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!

Post Reply