Page 1 of 1

Determining if a property is cascade deleted in templates

Posted: Mon 07 Jul 2014 15:15
by billster6809
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?

Re: Determining if a property is cascade deleted in templates

Posted: Tue 08 Jul 2014 12:39
by MariiaI
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.

Re: Determining if a property is cascade deleted in templates

Posted: Tue 08 Jul 2014 13:41
by billster6809
Thank you, just what I needed.

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