0

I am following a video on MVVM.

There I have written a simple method by following the steps in video as follows :

[OperationContract]
public IEnumerable<Patient> GetPatients()
{
    using (Lab_Lite_Entities db = new Lab_Lite_Entities())
    {
        var result = db.Patients.ToList();
        result.ForEach(p => db.Detach(p)); //I get an error here.
        return result;
    }
}

But I get an error as follows:

Lab_Lite_Data.Lab_Lite_Entities does not contain a definition for 'Detach' and no
extension method 'Detach' accepting a first argument of type
'Lab_Lite_Data.Lab_Lite_Entities' could be found 
(are you missing a using directive or an assembly reference?)

I have added a reference to System.Data.Entity and EntityFramework.

I am using Entity Framework 6.0.

Khushi
  • 1,031
  • 4
  • 24
  • 48

1 Answers1

1

As the error shows DbContext doesn't contain Detach method but there is an alternative way

Entity Framework Code First - No Detach() method on DbContext

Community
  • 1
  • 1
Selman Genç
  • 100,147
  • 13
  • 119
  • 184