Skip to content

Commit 9a90f93

Browse files
authored
Merge pull request #197 from TrackableEntities/fix-nav-fk-annotation
Fix missing FK data annotation on skip nav properties
2 parents d52940b + 1474873 commit 9a90f93

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

src/EntityFrameworkCore.Scaffolding.Handlebars/HbsCSharpEntityTypeGenerator.cs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -708,28 +708,25 @@ private void GenerateNavigationDataAnnotations(IEntityType entityType, ISkipNavi
708708

709709
private void GenerateForeignKeyAttribute(IEntityType entityType, ISkipNavigation navigation)
710710
{
711-
if (navigation.IsOnDependent)
711+
if (navigation.ForeignKey.PrincipalKey.IsPrimaryKey())
712712
{
713-
if (navigation.ForeignKey.PrincipalKey.IsPrimaryKey())
714-
{
715-
var foreignKeyAttribute = new AttributeWriter(nameof(ForeignKeyAttribute));
713+
var foreignKeyAttribute = new AttributeWriter(nameof(ForeignKeyAttribute));
716714

717-
if (navigation.ForeignKey.Properties.Count > 1)
718-
{
719-
foreignKeyAttribute.AddParameter(
720-
CSharpHelper.Literal(
721-
string.Join(",", navigation.ForeignKey.Properties.Select(p => EntityTypeTransformationService.TransformNavPropertyName(entityType, p.Name, p.ClrType.Name)))));
722-
}
723-
else
724-
{
725-
foreignKeyAttribute.AddParameter($"nameof({EntityTypeTransformationService.TransformNavPropertyName(entityType, navigation.ForeignKey.Properties.First().Name, navigation.ForeignKey.Properties.First().ClrType.Name)})");
726-
}
727-
728-
NavPropertyAnnotations.Add(new Dictionary<string, object>
729-
{
730-
{ "nav-property-annotation", foreignKeyAttribute }
731-
});
715+
if (navigation.ForeignKey.Properties.Count > 1)
716+
{
717+
foreignKeyAttribute.AddParameter(
718+
CSharpHelper.Literal(
719+
string.Join(",", navigation.ForeignKey.Properties.Select(p => EntityTypeTransformationService.TransformNavPropertyName(entityType, p.Name, p.ClrType.Name)))));
732720
}
721+
else
722+
{
723+
foreignKeyAttribute.AddParameter($"nameof({EntityTypeTransformationService.TransformNavPropertyName(entityType, navigation.ForeignKey.Properties.First().Name, navigation.ForeignKey.Properties.First().ClrType.Name)})");
724+
}
725+
726+
NavPropertyAnnotations.Add(new Dictionary<string, object>
727+
{
728+
{ "nav-property-annotation", foreignKeyAttribute }
729+
});
733730
}
734731
}
735732

0 commit comments

Comments
 (0)