I'm sure someone has seen this: Cannot remove an entity that has not been attached. with LINQ
问题 The scenario I am using LINQ is as follows: I have a method that queries a table and returns one record using the following code private L2SQLData.PatientFile getpatfile(long id) { var db = new HMSDataContext(); var patfile = (from f in db.PatientFiles.Where(f=> f.Id == id) select f).FirstOrDefault() ; return patfile; } Then another code calls the method above and takes object/record that was returned. Then deletes it from the same table as follows: L2SQLData.PatientFile patfile = getpatfile