Entity Framework ObjectContext re-usage

后端 未结 6 592
我寻月下人不归
我寻月下人不归 2020-12-24 15:45

I\'m learning EF now and have a question regarding the ObjectContext:

Should I create instance of ObjectContext for every query (function) when I access the database

6条回答
  •  难免孤独
    2020-12-24 16:03

    Don't use a singleton.. everyone using your app will share that and all sorts of crazy things will happen when that object context is tracking entities.

    I would add it as a private member

提交回复
热议问题