Visual Studio 和实体框架 edmx:我的自定义编辑被覆盖
我正在使用 Visual Studio 2010、Entity Framework 4 和模型优先开发。
我在 VS EDM 设计器中建模,然后自定义编辑我的 edmx 文件,以便表名称为大写(不是我的选择,DBA 要求数据库名称区分大小写)。 即 edmx ssdl 条目将如下所示:
<EntitySet Name="MESSAGES" EntityType="SIMPLEPIX.STORE.MESSAGES" store:Type="Tables" Schema="MW_ARCHIVE" Table="MESSAGES" />
然后,我在设计器中右键单击“从模型生成数据库...” 这做了两件事。首先,它将我所有的 edmx 编辑恢复为驼峰式大小写。即上面的行变为:(
<EntitySet Name="Messages" EntityType="SimplePix.Store.Messages" store:Type="Tables" Schema="MW_ARCHIVE" />
并注意我的 Table="MESSAGES" 属性已被删除)。
其次,它创建以下 DDL:
[snip]
IF OBJECT_ID(N'[MW_ARCHIVE].[MESSAGES]', 'U') IS NOT NULL
DROP TABLE [MW_ARCHIVE].[MESSAGES];
[snip]
CREATE TABLE [MW_ARCHIVE].[Messages] (
[snip]
没错:它知道必须删除 MESSAGES(大写),但随后想要创建 Messages(驼峰式大小写)。
如何让 VS 保留我的 edmx 编辑并生成正确的(大写)DDL?非常感谢。
I'm using Visual Studio 2010, Entity Framework 4, and model-first development.
I modelled in the VS EDM designer, then custom edited my edmx file so that the table names are uppercase (not my choice, DBA requirement on name-case-sensitive database).
i.e. an edmx ssdl entry will look like:
<EntitySet Name="MESSAGES" EntityType="SIMPLEPIX.STORE.MESSAGES" store:Type="Tables" Schema="MW_ARCHIVE" Table="MESSAGES" />
I then right-click in the designer to "Generate Database from Model..."
This does 2 things. First it reverts all my edmx edits back to camel case. I.e. the line above becomes:
<EntitySet Name="Messages" EntityType="SimplePix.Store.Messages" store:Type="Tables" Schema="MW_ARCHIVE" />
(and note my Table="MESSAGES" attribute has been removed).
Second it creates the following DDL:
[snip]
IF OBJECT_ID(N'[MW_ARCHIVE].[MESSAGES]', 'U') IS NOT NULL
DROP TABLE [MW_ARCHIVE].[MESSAGES];
[snip]
CREATE TABLE [MW_ARCHIVE].[Messages] (
[snip]
That's right: it knows it has to drop MESSAGES (uppercase), but then wants to create Messages (camel case).
How can I get VS to leave my edmx edits alone and generate the correct (uppercase) DDL? Thanks very.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法修改 EF 生成的类,因为每次执行“从数据库模型生成”时它们都会更改。我认为没有办法解决这个问题。
you can't modify the EF generated classes as they will be changed everytime you do the "Generate from database model". I do not think there is a way around this.
它在 POCO 类的顶部说了这一点(如果这就是您使用的
每当您重新生成代码时,您所做的任何更改都将被覆盖,每次不会失败,
我并不是说它不能通过一些晦涩的方法或工具完成,但我个人不知道
如果你的表必须是大写的,为什么不在数据库服务器上使用大写?或者我在这里遗漏了一些东西?
It says this at the top of your POCO classes (if that's what you're using
Whenever you regenerate your code any changes you made will be overwritten, every time without fail
I'm not saying it cannot be done through some obscure methods or tool, but none that I personally am aware of.
If you're tables have to be uppercase why not make then uppercase on the DB server? Or am I missing something here?