Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Table and Column Name Mappings Entity Framework v4.3

I've got an application with a working Entity model generated from an existing database. I have to point my application at a new database, with the same schema, except that the table and column names are different.

For example, my current schema has tables named like "Answer". My new schema that I need to point to has the exact same table, except it is named "tblAnswer".

My columns have also changed. Where as a column used to be called "AnswerId", it's now "zAnswerId". Don't ask about the "z" prefix, it's a long story, but it's on every column.

So, what options do I have to point this existing Entity Model (generated from the database) to a new database and adjust the mappings? I've been experimenting with some of the techniques that are used for "Code First" mappings, as outlined in this guide, but haven't had any luck. I simply don't know if this is the right approach, or if there is something that makes more sense.

Suggestions? Thanks in advance.

like image 725
letsgetsilly Avatar asked May 11 '12 16:05

letsgetsilly


1 Answers

You can change the database in the web.config file.

Use data annotations to use the different table and column names.

For example:

    [Table("tblAnswer")]
    class Answer
    {
      [Column("zAnswerId")]
      public int AnswerId { get; set; }
    }
like image 98
Jon Crowell Avatar answered Oct 14 '22 01:10

Jon Crowell