Do I need to force a Dispose after a LINQ query?

前端 未结 6 1935
野趣味
野趣味 2021-02-12 22:49

My DBA says that there are way too many connection open and he thinks it is my code in .net that is leaving them open.

I am using LINQ querys and EF code first.

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-12 23:08

    Check this out, here's a standard protocol on how to use IDisposable objects. https://msdn.microsoft.com/en-us/library/yh598w02.aspx

    It says:

    "As a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement."

    As they have access to unmanaged resources, you should always consider a "using" statement.

提交回复
热议问题