Determining if a property is cascade deleted in templates

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
billster6809
Posts: 29
Joined: Mon 27 Jan 2014 21:08

Determining if a property is cascade deleted in templates

Post by billster6809 » Mon 07 Jul 2014 15:15

I am adding some additional code generation to the method GenerateRelationProperty(), which is in the template for DbContext.

What I want to determine is whether the relation property is cascade deleted or not.

There is no Intellisense here (typing relationProperty. returns nothing), so I have been trying to figure this out by guessing.

I found relationProperty.Association, which is of type EntityAssociation (determined by adding a generated comment with the type name of .Association). Elsewhere in the template, in GenerateCascadeOnDeleteMapping(), which is passed an EntityAssociation, I see it use: association.DeleteCascaded

However, if I try relationProperty.Association.DeleteCascaded, the template gives an error that EntityDeveloper.Association does not contain that property.

So, how do I determine whether the association property is cascade deleted?

Also, a second question if I may. I am generating other custom code for each property based on Property extended properties. However, there are both EntityProperty and EntityRelationProperty classes. Is there a common base class I can pass to my custom <#+ method that can be used to .GetProperty("name") for either kind?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Determining if a property is cascade deleted in templates

Post by MariiaI » Tue 08 Jul 2014 12:39

However, if I try relationProperty.Association.DeleteCascaded, the template gives an error that EntityDeveloper.Association does not contain that property.
Rewrite the code in the following way:

Code: Select all

((EntityAssociation) relationProperty.Association).DeleteCascaded
The Association property of the relationProperty comes from the base level and has type of the base class Association. To get access to properties of the EntityAssociation, it is necessary to explicitly cast it.
However, there are both EntityProperty and EntityRelationProperty classes. Is there a common base class I can pass to my custom <#+ method that can be used to .GetProperty("name") for either kind?
The EntityProperty and EntityRelationProperty classes have the base class ModelObjectBase, which has the GetProperty method for retrieving extended properties.
Keep in mind, that if you want to use property with the same name for the Property and RelationProperty classes, you should define it for both classes, due to the fact that this is completely different types of model objects (i.e. RelationProperty is not Property).

If it is not what you mean, please describe your question in more details.

billster6809
Posts: 29
Joined: Mon 27 Jan 2014 21:08

Re: Determining if a property is cascade deleted in templates

Post by billster6809 » Tue 08 Jul 2014 13:41

Thank you, just what I needed.

And yes, I do have the same Extended properties defined for both Property and RelationProperty.

Post Reply