0

Im working with an ASP.NET boilerplate and would like to rename the sql tables it uses

I believe the relevant code is

public AlbumViewerContext(DbContextOptions options) : base(options)
    {         
    }

    public DbSet<Album> Albums { get; set; }
    public DbSet<Artist> Artists { get; set; }
    public DbSet<Track> Tracks { get; set; }
    public DbSet<User> Users { get; set;  }

It also includes models for Albums, Artists, Tracks and Users

How would i go about changing the SQL table names?

2 Answers 2

1

Add Table attribute on your Model. like as

[Table("Album")]
public class Album
{
 public string Title { get; set; }
}
Sign up to request clarification or add additional context in comments.

3 Comments

Id like the Album table renamed Report so how does that affect the code?
If you change your model name then you have to change the code as well. otherwise, there will be no issue.
So all i have to do is add your code and change table name?
0

.Net Core solution:

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.RenameTable(name: "OldTableName", schema: "dbo", newName: "NewTableName", newSchema: "dbo");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.RenameTable(name: "NewTableName", schema: "dbo", newName: "OldTableName", newSchema: "dbo");
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.