0

I'm working on a EF 6 project (ModelFirst).

I use a complex type named "UserInfo" in all my tables.

But, when I create my database from my model, columns are prefixed by the name of the complex type ( ex: UserInfo_CreationDate)

Is there a way to define in the model the column name without its prefix (CreationData in place of UserInfo_CreationDate)?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chrstpsln
  • 765
  • 16
  • 31

1 Answers1

0

You can use Annotations or the FluentApi.

For FluentApi, override the OnModelCreating method in your dbContext class and, for each property of class UserInfo, add a HasColumnName definition like this:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{    
    modelBuilder.Entity<YourEntity>().Property(s => s.UserInfo.CreationDate).HasColumnName("CreationData");  
}

For Annotations, in each property of class UserInfo, add an annotation like this:

public class UserInfo
{
    .....

    [Column("CreationDate")]
    public DateTime CreationDate {get; set;}

    .....
}  
ramaral
  • 6,149
  • 4
  • 34
  • 57