Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hey.

Anywone have a solution to how one can update a entity model, and then
renaming the foren keys konstraint to what it was when it was renamed the first time, without doing this manual every freeking time?

Eksample.
I have 2 database tables named User, and MailSendt.
The User table:
UserID (int)
Name (varchar)

The MailSendt table:
MailSendtID (int)
FromUserID (int) FK to UserID in User table
ToUserID (int) FK to UserID in User table

First time I generate the model it creates the forenkeys from MailSendt table to User table as "User" and "User1". I then rename these FK's to "FromUser" and "ToUser".

Now for some reason I have to update the model, and since I've made a lot of diffrent changes, the easy way is to delete the User table in the model, and then add it again (Hopfully Microsoft will update the Entity Framwork, so the updating of a model will be better, but untill then, it seem to be the best way of uppdating the model). This ofcource creates the FK's "User" and "User1".

So how can I create something that renames the it back to "FromUser" and "ToUser", without doing this manual?

In my database I've created the FK like "FK_MailSendt_FromUser" and "FK_MailSendt_ToUser", so the source behinde the model is "EdmRelationshipNavigationPropertyAttribute("MP.Core.DataModel", "FK_MailSendt_FromUser", "User")]
public User User
{

So I would think I could use this information to change the FK in the model.

Any help or links to articles, that would solve this problem, is greatly appreciated.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900