This article will show you how you can remove the remove the
mention error “The object cannot be deleted because it was not found in the
ObjectStateManager.” While performing the delete operation from .sdf database
using linq query in entity framework.
Some of my previous articles are as follow: Error
: Server-generated keys and server-generated values are not supported by SQL
Server Compact, Multiple
controls with the same ID '_header' were found. FindControl requires that
controls have unique IDs. in Asp.net.
So here is the solution for the error “The object cannot be
deleted because it was not found in the ObjectStateManager.”
StudentManagerEntitie objentity = new StudentManagerEntitie();
StudentDetail
objstudentdetail = new StudentDetail();
objstudentdetail.Id = Id;
objentity.StudentDetails.Attach(objstudentdetail);
objentity.DeleteObject(objstudentdetail);
/*Save
data to database*/
objentity.SaveChanges();
|
In above code please check the bold part of the code this
code will help you to remove the error.
This comment has been removed by the author.
ReplyDelete