I am building website and using entity framework. My question is regarding the entity context object usage. Is it best practice to create entity context object in each method or create it on page load and save it in view开发者_运维问答state? Will that be overhead if I create entity context object in each method?
You should create and dispose the ObjectContext with each page request, unless you profile your web site and it shows that you're having performance problems with doing so.
create it on page load and save it in viewstate?
Don't do this. (please, not ever)
Whether you create and dispose per method or not is open for debate, but it needs to at least be per request.
精彩评论