开发者

specify a different name for table|column name in EF4

开发者 https://www.devze.com 2023-02-05 15:30 出处:网络
I\'m using EF4 with CodeFirst public class 开发者_Go百科People : DbContext { public DbSet<Human> Humans { get; set; }

I'm using EF4 with CodeFirst

public class 开发者_Go百科People : DbContext
{
    public DbSet<Human> Humans { get; set; }
    public DbSet<Child> Children { get; set; }
}

At the moment, EF looks in the database for the Human table. How can I specify for it to look for Humans instead?


You can change table name on Human class:

[Table("Humans")]
public class Human
{
    ...
}

Other way is to use Fluent API:

modelBuilder.Entity<Human>()
    .ToTable("Humans");

Similary you can use ColumnAttribute or HasColumnName method to change the name of column.

0

精彩评论

暂无评论...
验证码 换一张
取 消