Should Entity Framework Context be Put into Using Statement?

前端 未结 9 1702
不思量自难忘°
不思量自难忘° 2020-11-29 23:52

The Entity Framework context object implements a Dispose() method which \"Releases the resources used by the object context\". What does it do really? Could it be a bad thin

9条回答
  •  囚心锁ツ
    2020-11-30 00:11

    Per Progamming Entity Framework: "You can either explicitly dispose the ObjectContext or wait for the garbage collector to do the job."

    So in short, while the using statement isn't required, it's best practice if you know you're done using the ObjectContext since the resource is freed up immediately instead of waiting for garbage collection.

提交回复
热议问题