You have two options here:
Data Annotations:
//Changing database table name to Metadata
[Table("Metadata")]
public class Metadata
{
[Required, Key]
public int MetadataId { get; set; }
[Required, ScaffoldColumn(false)]
public int DocumentId { get; set; }
[Required, StringLength(250), DataType(DataType.Text)]
public string Title { get; set;
}
or we have Fluent API:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Changing Database table name to Metadata
modelBuilder.Entity<Metadata>()
.ToTable("Metadata");
}
Using the Fluent API is the preferred option if you want to ensure your Domain Model stays uncluttered.
Just adding to this, if you solely want to remove the pluralisation of your table names, you can override EFs ability to do so with the following line of code:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…