Given the following snippet, where primitiveProperties and navProperties are set as in your default EntityFramework template, how do I determine the value '????', which is whether a primitive property is also a foreign key?
I need to flag the foreign key properties from my custom method, WriteEdmColumnDefinition
<# foreach (EntityProperty edmProperty in primitiveProperties) {
if (!edmProperty.IsComplexType) {
bool isForeignKey = ???? }
WriteEdmColumnDefinition(edmProperty, isForeignKey, true);
}
#>
I had a commented-out piece of code, but it is flagged as invalid by the template processor, so I'm not sure where I got it from:
bool isForeignKey = navProperties.Any(np=>np.GetDependentProperties().Contains(edmProperty));
Detecting foreign key in Entity Framework templates
-
- Posts: 30
- Joined: Mon 27 Jan 2014 21:08
Re: Detecting foreign key in Entity Framework templates
Please open the POCO Entity template (the predefined one) in Entity Developer and look at this code (at line 1581):
You can try implementing your scenario in a similar way.
Please tell us if this information helps.
Code: Select all
bool isForeignKey = false;
if (!property.IsComplexType) {
foreach (RelationProperty relProp in ((Class)property.ParentClass).RelationProperties) {
if (relProp.Association.Parent.Multiplicity != Multiplicity.Many &&
relProp.Association.Parent == relProp &&
relProp.Generate &&
relProp.OppositeRelationProperty.Properties.Contains(property)) {
isForeignKey = true;
break;
}
}
}
You can try implementing your scenario in a similar way.
Please tell us if this information helps.
-
- Posts: 30
- Joined: Mon 27 Jan 2014 21:08
Re: Detecting foreign key in Entity Framework templates
That worked perfectly. Thank you!
Re: Detecting foreign key in Entity Framework templates
Glad to see that the issue was resolved. If you have any further questions, feel free to contact us.