I create 2 table in sql server 2008
table 1 : User( UserID,Name, FirstName,Login, Password...) , PK : UserID
table 2 : SessionUser(UserID, Date, Adress) , PK : UserID
The relationship between the two tables is set in sql server 2008, with 1 to 1 relationship and the foreign key is in the table SessionUser (FK: userID)
There are users in the User table (full lines)
when I tried to add a session in the session table it shows me this error:
Entities in 'DistributionSSEntities.SessionUser
' participate in the 'FK_SessionUser_User
' relationship. 0 related 'User ' were found. 1 'User ' is expected.
code:
DistributionSSEntities db = new DistributionSSEntities();
SessionUser sessionUser = new SessionUser();
sessionUser.UserID = 12; // this ID existe in User table
sessionUser.Date = "12-12-2012";
sessionUser.AdressIP = "192.168.1.1";
db.AddToSessionUser(sessionUser);
db.SaveChanges();
how to resolve this problem Thanx.