Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace {{namespace}}
{
{{#if class-annotation}}
{{{class-annotation}}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,16 @@ private void GenerateForeignKeyAttribute(INavigation navigation)
{
var foreignKeyAttribute = new AttributeWriter(nameof(ForeignKeyAttribute));

foreignKeyAttribute.AddParameter(
CSharpHelper.Literal(
string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name))));
if (navigation.ForeignKey.Properties.Count > 1)
{
foreignKeyAttribute.AddParameter(
CSharpHelper.Literal(
string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name))));
}
else
{
foreignKeyAttribute.AddParameter($"nameof({navigation.ForeignKey.Properties.First().Name})");
}

NavPropertyAnnotations.Add(new Dictionary<string, object>
{
Expand All @@ -423,7 +430,11 @@ private void GenerateInversePropertyAttribute(INavigation navigation)
{
var inversePropertyAttribute = new AttributeWriter(nameof(InversePropertyAttribute));

inversePropertyAttribute.AddParameter(CSharpHelper.Literal(inverseNavigation.Name));
inversePropertyAttribute.AddParameter(
!navigation.DeclaringEntityType.GetPropertiesAndNavigations().Any(
m => m.Name == inverseNavigation.DeclaringEntityType.Name)
? $"nameof({inverseNavigation.DeclaringEntityType.Name}.{inverseNavigation.Name})"
: CSharpHelper.Literal(inverseNavigation.Name));

NavPropertyAnnotations.Add(new Dictionary<string, object>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace {{namespace}}
{
{{#if class-annotation}}
{{{class-annotation}}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class {{class}} : DbContext
namespace {{namespace}}
{
{{#if class-annotation}}
{{{class-annotation}}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
Expand Down
2 changes: 1 addition & 1 deletion test/Scaffolding.Handlebars.Tests/ExpectedEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public partial class Product
public byte[] RowVersion { get; set; }
public int? CategoryId { get; set; }

[ForeignKey(""CategoryId"")]
[ForeignKey(nameof(CategoryId))]
[InverseProperty(""Product"")]
public virtual Category Category { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class {{class}} : DbContext
namespace {{namespace}}
{
{{#if class-annotation}}
{{{class-annotation}}}
{{spaces 4}}{{{class-annotation}}}
{{/if}}
public partial class {{class}}
{
Expand Down