开发者

How to prevent Entity Designer from scripting the columns alphabetically?

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 name开发者_如何学Gos 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜