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?
Determining if a property is cascade deleted in templates
-
billster6809
- Posts: 30
- Joined: Mon 27 Jan 2014 21:08
Re: Determining if a property is cascade deleted in templates
Rewrite the code in the following way:However, if I try relationProperty.Association.DeleteCascaded, the template gives an error that EntityDeveloper.Association does not contain that property.
Code: Select all
((EntityAssociation) relationProperty.Association).DeleteCascadedThe EntityProperty and EntityRelationProperty classes have the base class ModelObjectBase, which has the GetProperty method for retrieving 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?
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: 30
- Joined: Mon 27 Jan 2014 21:08
Re: Determining if a property is cascade deleted in templates
Thank you, just what I needed.
And yes, I do have the same Extended properties defined for both Property and RelationProperty.
And yes, I do have the same Extended properties defined for both Property and RelationProperty.