none
Self-Tracking Entities + REST Service + Delete operation RRS feed

  • Question

  • Hi,

    I have a WCF REST service 4.0 application which exposes some CRUD operations over STE POCOs. I have a problem with the DELETE operation (Update works fine). My code : 

     

    Service operation for deleting a vehicule by Id :

        public void DeleteVehiculeById(string id)
        {
          using (MyEntities context= new MyEntities ())
          {
            try
            {
              Vehicule v = GetVehiculeById(id);
              v.MarkAsDeleted<Vehicule>();
              context.Vehicule.ApplyChanges(v);
              context.SaveChanges();
    
            }
            catch (Exception ex)
            {
              throw new WebFaultException<string>("Erreur during delete operation, HttpStatusCode.BadRequest);
            }
          }
        }
    
    
    
    


    This code doesn't work and it doesn't return any error message. I thought that markAsDeleted() + ApplyChanges() will do the job ... Any help will be appreciated.

     

    Thank you

    Monday, July 4, 2011 2:23 PM

Answers

  • Hello,

    self tracking functionality is turned on automatically only during deserialization so if you are using STEs on the server you should use them as any other entity (it means simply call DeleteObject on the context instead of using ApplyChanges but the object must be attached to the context) or you should manually turn on self tracking by calling StartTracking on STE.

    Best regards,
    Ladislav

    • Proposed as answer by Rune Gulbrandsen Monday, July 4, 2011 8:44 PM
    • Marked as answer by cabrinha Wednesday, July 6, 2011 1:31 PM
    Monday, July 4, 2011 2:49 PM

All replies

  • Hello,

    self tracking functionality is turned on automatically only during deserialization so if you are using STEs on the server you should use them as any other entity (it means simply call DeleteObject on the context instead of using ApplyChanges but the object must be attached to the context) or you should manually turn on self tracking by calling StartTracking on STE.

    Best regards,
    Ladislav

    • Proposed as answer by Rune Gulbrandsen Monday, July 4, 2011 8:44 PM
    • Marked as answer by cabrinha Wednesday, July 6, 2011 1:31 PM
    Monday, July 4, 2011 2:49 PM
  • Ok, using DeletObject it works! Thank you
    Wednesday, July 6, 2011 1:31 PM