Skip to content

Strong typing names in data annotations during reverse engineering where possible #32126

Closed as not planned

Description

With data annotations you get db-first code like this:

[Index("Id")]
[PrimaryKey("Id")]
public class Post
{
    public int Id { get; set; }

    [ForeignKey("BlogKey")]
    public Blog Blog { get; init; }
}

It would be much more error-prone to use “strongly typed” nameof version when possible during reverse engineering:

  • PrimaryKey(nameof(First), nameof(Second)].
  • string interpolation for foreign keys [ForeignKey($"{nameof(First)}, {nameof(Second)}")].

This is especially useful if user would like to rename the property after scaffolding:

class Item
{
    [Column("ActualNameInDb")]
    public string Property {get; set;}
}

Also one could easily see “usages” of the property when it’s referenced not via a magic string but a nameof.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions