1

I am currently using this approach to dispose off the connection with datacontext object.

using (var db = GetDbContext(_connectionString))
{
    List<Procedure_Name> result =
        (from x in db.storedprocedure select x)
            .ToList<Procedure_Name>();
    return result;
}

I want to know is this the correct way to dispose of connection object or guide me the best possible approach to be used in this context.

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
Aqib Shehzad
  • 79
  • 1
  • 8
  • 4
    Have a look at [this](http://stackoverflow.com/questions/3247617/what-happens-if-i-return-before-the-end-of-using-statement-will-the-dispose-be) – GregoryHouseMD Mar 12 '16 at 11:51
  • Yes this is the correct way. Just a note here: you can't use *lazy loading* and load the related entity lazily because the db is disposed. – Salah Akbari Mar 12 '16 at 12:20

0 Answers0