如何防止实体设计器按字母顺序编写列脚本?
我在 SQL 设计器中创建了 3 个表 -
Community { ID, Name, Description }
Audience { ID, Type, Value}
Community_Audience { CommunityID, AudienceID }
我将此架构导入到 Visual Studio 2010 中的 EDMX 设计器中,在设计器中右键单击并选择“从模型生成数据库”以编写架构脚本。当我查看生成的脚本时,它是这样编写的 -
Community { ID, Name, Description } -- Column names not sorted alphabetically.
Audience { ID, Type, Value} -- Column names not sorted alphabetically.
Community_Audience { AudienceID, CommunityID } -- Column names sorted alphabetically. CommunityID is after AudienceID.
这导致我的数据播种脚本失败,因为我没有指定列名称 - INSERT INTO Community_Audience { 'guid', 'guid' }
我知道我可以更新我的数据播种脚本以包含列名称或重新排列 edmx 文件中的底层 xml,但我不想走这条路,因为我将清除 edmx 中的实体(表)并过于频繁地从数据库导入新架构。我想知道是否有设置可以阻止设计师按字母顺序排序。奇怪的是,它只发生在交叉引用表(如 Community_Audience)上,而不发生在主要表(如本例中的 Community 和 Audience)上。
感谢您的任何帮助。
I created 3 tables in SQL Designer -
Community { ID, Name, Description }
Audience { ID, Type, Value}
Community_Audience { CommunityID, AudienceID }
I imported this schema into the EDMX designer in Visual Studio 2010, right-clicked in the designer and selected "Generate Database from Model" to script out the schema. When I looked at the generated script, it is scripting it out like this -
Community { ID, Name, Description } -- Column names not sorted alphabetically.
Audience { ID, Type, Value} -- Column names not sorted alphabetically.
Community_Audience { AudienceID, CommunityID } -- Column names sorted alphabetically. CommunityID is after AudienceID.
This is causing my data seeding scripts to fail as I'm not specifying the column names -
INSERT INTO Community_Audience { 'guid', 'guid' }
I understand I can update my data seeding scripts to include column names or re-arrange the underlying xml in the edmx file but I don't want to go that route as I'll be clearing out the entities (tables) in the edmx and importing fresh schema from the database too often. I was wondering if there is setting that will prevent the designer from sorting alphabetically. Strangely, it only happens to the cross ref tables (like Community_Audience) and not the primary ones (like Community and Audience in this case).
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经描述了您的两个选择 - 要么修改您的 INSERT 语句,这不应该那么难,您只需执行一次,要么尝试修改 EDMX(如果您使用从数据库刷新模型,这是不好的方法)。实体设计器确实没有定义列排序的功能。生成数据库脚本由单独的组件驱动。它基于 Windows Workflow Foundation 4,可以用您的自定义工作流替换,但这是一项大量的工作,没有任何真正的原因。解决方案是修改 INSERT 语句。
我不明白的是为什么同时使用从模型生成数据库以及从数据库刷新模型。
You have described both your choices - either modify your INSERT statements which should not be so hard and you will have to do it only once or try to modify EDMX (bad way if you use refreshing model from database). Entity designer really doesn't have a feature to define ordering in columns. Generating the database script is driven by separate component. It is based on Windows Workflow Foundation 4 and it can be replaced with your custom workflow but it is a lot of work without any real reason. The solution is modifying INSERT statements.
What I don't understand is why do you use Generate Database from Model in the same time as well as refreshing model from database.