更改表和列名映射实体框架v4.3 [英] Change Table and Column Name Mappings Entity Framework v4.3

查看:70
本文介绍了更改表和列名映射实体框架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.

例如,我当前的模式有名为像答案。我需要指向的新模式具有完全相同的表,除了它被命名为tblAnswer。

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".

我的列也已更改。哪里用作AnswerId的列,现在是zAnswerId。不要问z前缀,这是一个很长的故事,但它是在每一列。

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.

建议?感谢提前。

推荐答案

您可以更改web.config文件中的数据库。

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

使用数据注释来使用不同的表格和列名。

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

例如:

    [Table("tblAnswer")]
    class Answer
    {
      [Column("zAnswerId")]
      public int AnswerId { get; set; }
    }

这篇关于更改表和列名映射实体框架v4.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆