我正在尝试更新 2 个表:RESTAURANT 和 HOURS。这些表包含 REST_ID 键。我在箭头 (==>) 行出现错误:对不起,我正在尝试自学这些东西,这是我第一次尝试多表插入。
无法添加或附加该对象,因为其 EntityReference 的 EntityKey 属性值与该对象的 EntityKey 不匹配。
RESTAURANT addRest = new RESTAURANT();
addRest.REST_NAME = r_name;
addRest.REST_STREET1 = r_street;
addRest.CITY_ID = c_id;
addRest.REST_PHONE = r_phone;
addRest.REST_WEBSITE = r_web;
addRest.HOUR = new HOUR();
addRest.HOUR.HOURS_SUN = h_su;
addRest.HOUR.HOURS_MON = h_mo;
addRest.HOUR.HOURS_TUE = h_tu;
addRest.HOUR.HOURS_WED = h_we;
addRest.HOUR.HOURS_THU = h_th;
addRest.HOUR.HOURS_FRI = h_fr;
addRest.HOUR.HOURS_SAT = h_sa;
addRest.HOURReference.EntityKey = new EntityKey("FVTCEntities.HOURS", "HOURS", 1);
==> db.AddToRESTAURANTs(addRest);
db.SaveChanges();