Table name
[Table("blogs")] public class Blog { public int BlogId { get; set; } public string Url { get; set; } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .ToTable("blogs"); }
Table schema
[Table("blogs", Schema = "blogging")] public class Blog { public int BlogId { get; set; } public string Url { get; set; } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Blog>() .ToTable("blogs", schema: "blogging"); }
Rather than specifying the schema for each table, you can also define the default schema at the model level with the fluent API:
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("blogging"); }
Column name
public class Account { [Column("MyPasswordHashColumn")] public string PasswordHash { get; set; } }
public class YourContext : DbContext { protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<Language>(x => x .ToTable("MyAccountsTable") .Property(entity => entity.PasswordHash) .HasColumnName("MyPasswordHashColumn") ); } }
References
https://docs.microsoft.com/en-us/ef/core/modeling/entity-types?tabs=data-annotations
https://stackoverflow.com/questions/42190909/how-to-specify-entity-framework-core-table-mapping