我想插入數據的三個關係表,但我不能這樣做:/C#實體框架插入關係表?
這裏是代碼
hali_sahaEntities con = new hali_sahaEntities();
Users user = new Users();
Emails email = new Emails();
Phones phone = new Phones();
user.Name = textBox1.Text;
user.Surname = textBox7.Text;
user.IdentityNumber = Convert.ToInt32(textBox2.Text);
user.Adress = textBox5.Text;
user.Comment = textBox6.Text;
email.TCKN = Convert.ToInt32(textBox2.Text);
email.Email = textBox4.Text;
phone.TCKN = Convert.ToInt32(textBox2.Text);
phone.Phone = textBox3.Text;
con.Users.Add(user);
con.Emails.Add(email);
con.Phones.Add(phone);
con.SaveChanges();
我可以插入數據表的用戶,但電子郵件和電話,表不能插入數據?
表之間的關係如何?一對一? – Eldeniz
我使用一對多 – oEs
您是否在您的實體模型中創建關係? – Eldeniz