Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added nameof syntax in scaffolding data annotations attributes #14609

Merged
merged 1 commit into from
May 10, 2019
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 @@ -331,9 +331,16 @@ private void GenerateForeignKeyAttribute(INavigation navigation)
{
var foreignKeyAttribute = new AttributeWriter(nameof(ForeignKeyAttribute));

foreignKeyAttribute.AddParameter(
_code.Literal(
string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name))));
if (navigation.ForeignKey.Properties.Count > 1)
{
foreignKeyAttribute.AddParameter(
smitpatel marked this conversation as resolved.
Show resolved Hide resolved
_code.Literal(
string.Join(",", navigation.ForeignKey.Properties.Select(p => p.Name))));
}
else
{
foreignKeyAttribute.AddParameter($"nameof({navigation.ForeignKey.Properties.First().Name})");
}

_sb.AppendLine(foreignKeyAttribute.ToString());
}
Expand All @@ -350,7 +357,7 @@ private void GenerateInversePropertyAttribute(INavigation navigation)
{
var inversePropertyAttribute = new AttributeWriter(nameof(InversePropertyAttribute));

inversePropertyAttribute.AddParameter(_code.Literal(inverseNavigation.Name));
inversePropertyAttribute.AddParameter($"nameof({inverseNavigation.DeclaringEntityType.Name}.{inverseNavigation.Name})");

_sb.AppendLine(inversePropertyAttribute.ToString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Navigation_properties()
{
x.Property<int>("Id");

x.HasOne("Person", "Author").WithMany();
x.HasOne("Person", "Author").WithMany("Posts");
x.HasMany("Contribution", "Contributions").WithOne();
}),
new ModelCodeGenerationOptions
Expand Down Expand Up @@ -53,7 +53,8 @@ public Post()
public int Id { get; set; }
public int? AuthorId { get; set; }

[ForeignKey(""AuthorId"")]
[ForeignKey(nameof(AuthorId))]
[InverseProperty(nameof(Person.Posts))]
public virtual Person Author { get; set; }
public virtual ICollection<Contribution> Contributions { get; set; }
}
Expand Down