Why does no one disposes DbContext after WebApi controller operation?

后端 未结 6 2507
梦谈多话
梦谈多话 2021-02-19 20:32

I am aware of various tutorials as well as complete examples targeting WebApi & Entity Framework (even from Microsoft) that have WebApi

6条回答
  •  名媛妹妹
    2021-02-19 20:42

    You are supposed to Dispose() of your context class, so use the using construct:

    using (var context = new InternetDbContext())
    {    
        // your code here, try/catch is auto-generated by the compiler
    }
    

提交回复
热议问题