0

I am looking at EF (not done before but do understand c#) but I am finding it hard to change the names I have given tables and properties in the database to c# name.

I use prefix's for my database e.g. a user table will be called "tblUsers" will have columns of "usrID" , "usrName" ... but in C# EF it looks like tblUsers.usrID / tblUsers.usrName which is not needed. I would like it to look like User.Id / User.Name. I have got it to do this by changing OnModelCreating to register the property name / table name but this means I cant easily update EF to match any changes I do in the database.

Does anyone have a good way of doing this so I can easily update the model?

Thomas James
  • 387
  • 8
  • 19
  • 1
    Entity framework maps database object as an entity(class) in .edmx file. So you cannot set different column name in database and different name in application. – Rohit Sonaje Jun 05 '15 at 11:23
  • I am able to set different names, its the refreshing the EF model that will wipe my settings which I dont want it to do, I just want it to add / change what I have done in the database. modelBuilder.Entity().ToTable("tblUsers"); modelBuilder.Entity().Property(usr => usr.Id).HasColumnName("uID"); – Thomas James Jun 05 '15 at 11:27

1 Answers1

0

I have a similar problem, but just with a couple tables. What I do is to save and keep my modified partial classes apart and then exclude those tables from EF model generation. Now I have to be aware from any changes on the database.