Should Entity Framework Context be Put into Using Statement?

前端 未结 9 1693
不思量自难忘°
不思量自难忘° 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:12

    When you dispose, the ObjectContext disposes other owned objects.

    Including things like the EntityConnection which wraps the actual database connection, i.e. generally a SqlConnection.

    So 'if' the SqlConnection is open it will be closed when you dispose the ObjectContext.

提交回复
热议问题