实体框架上下文为静态 [英] Entity framework context as static
问题描述
在Web应用程序中,如果我将实体框架模型的上下文声明为静态,那将会很好吗?会没事的它不推荐?为什么?
谢谢!
几乎绝对不会。
随着更多对象的查询/保存,ObjectContext越来越大。
同样在线程之间共享一个ObjectContext,就像您所做的一样,不推荐使用,因为锁定问题和不确定性的副作用您将不得不处理。 / p>
我写了一个关于这个话题的提示。
提示18 - 如何为您的ObjectContext决定一生一次
In a web application it would be ok if i declare the context of a entity framework model as static? it would be ok? its not recommended? why? Thanks!
Almost definitely not.
ObjectContexts get bigger and bigger as more Objects are queried / saved.
Also sharing an ObjectContext between threads, as you would be doing, is not recommended, because of the locking issues and undeterministic side-effects you would have to deal with.
I wrote a tip on this topic a while back.
Tip 18 - How to decide on a lifetime for your ObjectContext
这篇关于实体框架上下文为静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!