Weird strange things happening in repository record!

倖福魔咒の 提交于 2020-01-15 09:37:47

问题


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: 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](RepositoryRecord1 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

Here's my code:

        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

回答1:


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.



来源:https://stackoverflow.com/questions/924640/weird-strange-things-happening-in-repository-record

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!