Is Disposing of Entity Framework context object required

后端 未结 5 1513
臣服心动
臣服心动 2021-02-07 09:39

We are using entity framework for communication with database in our WCF service methods, recently we run the code review tool on our service code. As usual we got many review p

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 10:07

    In general if something implements IDisposable it's a Good Idea(TM) to explicitly dispose of it when you're through. This is especially true if you do not own the implementation of said object; you should treat it as a black box in this case. Additionally, even if it were not necessarily "required" to dispose of it now, it may be in the future.

    Therefore, IMHO the question of whether you "need to" explicitly dispose of the object is irrelevant. If it is asking to be disposed of - by virtue of implementing IDisposable - it should be disposed of.

提交回复
热议问题