问题描述
亚音速 2.2.我使用存储库记录模式,其中有一个表约会",其中的约会 ID 作为自动递增的 int.
SubSonic 2.2. I use the repository record pattern, with a table "appointment" with an appointmentId as auto-incrementing int.
我正在尝试更新它,但是当我使用完全不同的内容更新字段时,脏列始终为零,并且出现异常.
I am trying to update it, but when I do update the fields with something totally different, dirty columns are always zero, and I get an exception.
System.NullReferenceException:未将对象引用设置为对象的实例.在 SubSonic.DataService.ExecuteQuery(QueryCommand cmd) 在 SubSonic.SubSonicRepository.Update[T](RepositoryRecord1 item, String userName) at janji.Janji.Data.DB.Update[T](RepositoryRecord
1项目)在 A:\Source\VS2008\Web\Apps\janji\janji\Classes\DAL\AllStructs.vb:line 197 at janji.WebForm4.SaveData() in A:\Source\VS2008\Web\Apps\janji\janji\UI\Appt.aspx.vb:line 343
System.NullReferenceException: Object reference not set to an instance of an object. at SubSonic.DataService.ExecuteQuery(QueryCommand cmd) at SubSonic.SubSonicRepository.Update[T](RepositoryRecord1 item, String userName) at janji.Janji.Data.DB.Update[T](RepositoryRecord
1 item) in A:\Source\VS2008\Web\Apps\janji\janji\Classes\DAL\AllStructs.vb:line 197 at janji.WebForm4.SaveData() in A:\Source\VS2008\Web\Apps\janji\janji\UI\Appt.aspx.vb:line 343
这是我的代码:
Try
If Appointment.AppointmentId > 0 Then
Appointment.AddressName = uxHotel.Text
Appointment.Address = uxAddress.Text
Appointment.AppStartTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptStartTime.SelectedDate.Value.ToShortTimeString)
Appointment.ApptEndTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptEndTime.SelectedDate.Value.ToShortTimeString)
Appointment.Completed = uxCOmpleted.Checked
Appointment.DropNumber = uxDropNum.Text
Appointment.Total = 0
Appointment.EmployeeId = 0
Appointment.Model = uxModel.Text
Appointment.DropAmount = Decimal.Parse(uxDropAmount.SelectedValue)
Appointment.RoomNumber = uxRoom.Text
'If Appointment.DirtyColumns.Count > 0 Then
Janji.Data.DB.Update(Of Janji.Data.Appointment)(Appointment)
'End If
End If
Catch ex As Exception
_ErrorMessage = ex.ToString
RetVal = False
lErrors.Text = _ErrorMessage
lErrors.Visible = True
End Try
推荐答案
您正在使用我们提供的 Structs,而不是实例化 Appointment 对象.在这里执行您正在执行的所有操作,但创建一个 Appointment 实例并为其分配值.然后将该实例传递给存储库.
You're using the Structs we provide instead of instantiating an Appointment object. Do everything you're doing here, but create an Appointment instance and assign it the values. Then pass that instance to the repo.
这篇关于存储库记录中发生了奇怪的事情!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!