insert the value on the foreign key


problem is with foreign key:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_uzytkownik_Logowanie". The conflict occurred in database "Restauracja", table "dbo.Logowanie", column 'LoginID'.
The statement has been terminated.

I check this using breakpoints, and primary key in Logowanie table was added when breakpoints (running application) was after


Primary key of LoginID in logowanie table is added automatically during SubmitChanges.

How to copy value of LoginID from logowanie table to LoginID in uztkownik table? I add foreign key value here, but here LoginID hasn't value yet.

Logowanie newlog = new Logowanie()
   Login = model.LoginModel.Użytkownik,
   Haslo = model.LoginModel.Hasło,
   konto = model.LoginModel.Konto

uzytkownik user = new uzytkownik()
   imie = model.uzytkownikModle.imie,
   nazwisko = model.uzytkownikModle.nazwisko,
   pesel = model.uzytkownikModle.pesel,
   nip = model.uzytkownikModle.nip,
   telefon = model.uzytkownikModle.telefon,
   adres_zamieszkania = model.uzytkownikModle.adres_zamieszkania,
   email =,
   LoginID = newlog.LoginID //<<<----------------



uzytkownik should have a property called Logowanie, which you can set to the new instance you created but didn't Submit yet:

user.Logowanie = newlog;