实体框架工作单位和空白

时间:2012-07-18 17:13:39

标签: entity-framework unit-of-work

所以我有点卡住,它要么是非常简单的,要么是缺失的,要么是大块的代码。

即时更新现有记录(两张表)

using (IUnitOfWork uw = _uwf.Create())
            {
                DomainObjects.Appointment newAppointment = uw.Appointment.FindAppointmentById(Id);
                newAppointment.AppointmentItems.Clear();

                newAppointment.ClientId = clientId;
                newAppointment.AllDay = false;
                newAppointment.StartTime = startTime;
                newAppointment.EndTime = endTime;
                newAppointment.Notes = notes;
                newAppointment.PetId = petId;
                foreach (DomainObjects.AppointmentItem item in appointmentItems)
                {
                    item.AppointmentId = newAppointment.Id;
                    newAppointment.AppointmentItems.Add(item);
                }


                uw.Commit();
            }

问题在于使用了约会项目,就像我得到数据库更新一样

  

“{”无法将值NULL插入列'AppointmentId',表中   'database.dbo.AppointmentItems';列不允许空值。 UPDATE   失败了。\ r \ n声明已经终止。“}”

然而,AppointmentId有一个字符串值。 sql看起来像

exec sp_executesql N'update [dbo].[AppointmentItems]
set [AppointmentId] = null
where ([Id] = @0)
',N'@0 nvarchar(50)',@0=N'45f56af1-7fe5-46c3-9a02-a1df09a4fbfa'

任何想法?

0 个答案:

没有答案