0

I have created a new table in the membership database. Now I want to make a relationship with the _aspnet_Users_ table. I've made the relationship, but when I make an asp.net entity model from the database, the Model1.edmx shows the tables without relationship.

Is this possible ?

pb2q
  • 58,613
  • 19
  • 146
  • 147
Milanix
  • 31
  • 2
  • 9

1 Answers1

0

Here is what you are going to do : After adding the table to your database in server explorer or management studio and setting the relationship you should reopen the Model1.edmx and right click in the design area and click on Update model from database then check tables and click finish , visual studio will autpmatically add new tables and relationships to your Model.edmx

And the problem is that you can not make a relationship between two table columns that none of them are key column !

The aspnet_User is the primary key table and the Post table is the foriegn key table , so you should make the relationship between the UserID column of the aspnet_User table and a same type (uniqeidentifier) column in the Posts table which represents The user's ID who posted the post .

gwt
  • 2,331
  • 4
  • 37
  • 59
  • Still doesnt want, well let me explain better, i add one more column in the aspnet_Users table "NumberID" and its from type int identity. I do this since i need one unique number of every user, that it is number, not uniqueidentifier like userID. Then in the new table "posts" i want to connect the field "postedBy" and the "NumberID". But what i got in Model1.edmx is 2 tables without relationship – Milanix Jun 10 '12 at 10:43
  • The solution is what I told you ! after editing your database (adding the Post table and editting aspnet_User table and setting the relationship between them) you should Update your model from database again and It will deffinitly work ! If you have done what I said and still you have this issue the only problem I can guess is that you may have not set the relationship in sqlserver properly between those two tables ! – gwt Jun 10 '12 at 10:51
  • Entering aspnet_Users, adding new column NumberID, setting int identity, saving, going indexes and keys, setting NumberID as index unique, generating the Model1.edmx, going back to the database, creating new table aspnet_Posts, postID primary key identity, posterID int, text etc, going to relationship, add, tables and columns specific, primary key table is aspnetUsers with NumberID selected, and foreign table aspnet_Posts with posterID selected. The relationship is saved, going to update the Model1.edmx, it adds the table with no relationship :/ – Milanix Jun 10 '12 at 11:19
  • Error: The relationship 'FK_aspnet_Posts_aspnet_Users' has columns that are not part of the key of the table on the primary side of the relationship. The relationship was excluded. – Milanix Jun 10 '12 at 12:07
  • It's because Your User Table is the primary key table and you should use It's key column to make a relationship and you can not use a NON KEY Column to make a relationship ! So you can not use the field NumberID to make a relationship ! you got It ?!!! ;) – gwt Jun 10 '12 at 15:24
  • If this solved your problem please mark it as answer , so other people who have the same problem can use this answer , good luck – gwt Jun 10 '12 at 15:28