Can't delete a record

3 posts, 0 answers
  1. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 11 Mar 2012 Link to this post

    This is my first real attempt at using OA and I'm a bit stuck.

    I'm trying to delete a record using code like this...
    public void RadScheduler1_AppointmentDelete(object sender, AppointmentDeleteEventArgs e)
        LCCalendarEvent eventToDelete = Appointments.FirstOrDefault(a => a.Id == (int)e.Appointment.ID);
        if (eventToDelete != null)
            using (LCDAL dbContext = new LCDAL())

    but when it tries executing the .Delete method, I get this...

    Telerik.OpenAccess.Exceptions.InvalidOperationException was unhandled by user code
      Message=Object references between two different object scopes are not allowed. The object 'LCCustomDAL.LCCalendarEvent' is already managed by 'ObjectScopeImpl 0x9' and was tried to be managed again by 'ObjectScopeImpl 0xa OpenAccessRuntime.EnlistableObjectScope'.
           at OpenAccessRuntime.ExceptionWrapper.Throw()
           at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x)
           at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.deletePersistent(Object pc)
           at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.deletePersistent(Object o)
           at OpenAccessRuntime.ObjectScope.Remove(Object pc)
           at Telerik.OpenAccess.OpenAccessContextBase.Delete(Object entity)
           at RadControlsWebApp3.Calendar1.RadScheduler1_AppointmentDelete(Object sender, AppointmentDeleteEventArgs e) in C:\Users\Stuart\Documents\Visual Studio 2010\Projects\RadControlsWebApp3\RadControlsWebApp3\Calendar1.ascx.cs:line 64
           at Telerik.Web.UI.RadScheduler.OnAppointmentDelete(AppointmentDeleteEventArgs args)
           at Telerik.Web.UI.Scheduling.AppointmentController.DeleteAppointment(Appointment appointmentToDelete, Boolean deleteSeries)
           at Telerik.Web.UI.RadScheduler.DeleteAppointment(Appointment appointmentToDelete)
           at Telerik.Web.UI.RadScheduler.ProcessPostBackCommand(SchedulerPostBackEvent postBack)
           at Telerik.Web.UI.RadScheduler.RaisePostBackEvent(String eventArgument)
           at Telerik.Web.UI.RadScheduler.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Clearly, I'm doing something wrong, but I'll be damned if I can figure out what it is.

    I'd appreciate and clues.


  2. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 11 Mar 2012 Link to this post

    Whilst I've not tried it yet, I've a suspicion that whatever it is that I'm doing wrong/not doing right is going to stop me from updating a record too.

  3. DevCraft banner
  4. Ralph Waldenmaier
    Ralph Waldenmaier avatar
    202 posts

    Posted 12 Mar 2012 Link to this post

    Hi Stuart,

    Based on the code you provided, I assume that you have already an open Context when you access the RadScheduler1_AppointmentDelete method. You load the eventToDelete using the existing Context, which is then bound to the Context where it is loaded from. Now you open a second Context and try to delete the object that is maintained by your first Context. This scenario is not supported in Telerik OpenAccess ORM. To delete the object, please use the Context which manages this instance or retrieve the same database object again via primary keys into the second context to delete it.

    I hope this information is useful for you. Feel free to ask if you have any other question.

    Kind regards,
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top