Monday, May 14, 2012

How to map column names with EF 4.3.1?

I've got problem with simple mapping (using EF 4.3.1 - code first approach)



public class Someclass
{
public virtual int ID { get; set; }
public virtual string Name { get; set; }
}


And Table someclass with int ID and varchar someclass_name.
Now what I want to do is map Name with someclass_name



 modelBuilder.Entity<Someclass>()
.Property(r => r.Name).HasColumnName("someclass_name");


But id doesn't work and exception says: "context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)."



I've also tried doing that by:



modelBuilder.Configurations.Add(new SomeclassMap());

public class SomeclassMap : EntityTypeConfiguration<Someclass>
{
public SomeclassMap() {
// this.Property(r => r.Name).HasColumnName("someclass_name");
Map(r =>
{
Property(m => m.Name).HasColumnName("restaurant_name");
});
}
}


Can somebody tell me what am I doing wrong? THX





No comments:

Post a Comment