Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Does it make sense to create new object before trying to save object that I already have loaded but with more then one Context?</p> </blockquote> <p>No. But it shows <strong>you have a design problem</strong> in your application. <strong>You shouldn't have to deal with multiple contexts for the same objects</strong>.</p> <p>I think you have a problem with your contexts lifetime. This isn't an easy issue to solve, but here is <a href="http://blogs.msdn.com/b/alexj/archive/2009/05/07/tip-18-how-to-decide-on-a-lifetime-for-your-objectcontext.aspx" rel="nofollow">an article</a> that could help you. See also <a href="http://social.msdn.microsoft.com/Forums/ar/adodotnetentityframework/thread/333e4fce-ac9c-4875-862e-76fcadaa619c" rel="nofollow">here</a>.</p> <p>My opinion is that contexts should have the shortest lifetime as possible. Long-running contexts are generally a <strong>bad practice</strong>, as you'll quickly encounter issues in your application (memory leak, problems when dealing with multi-threading or concurrency...etc.)</p> <p>If you have a 3-tiers architecture, then you really should expose <strong>stateless</strong> services and <strong>create a new context per request</strong>. If you're accessing directly the database from your application (2-tiers application), for instance a Winform application that requests the DB directly, <strong>shorten the lifetime of your context as much as possible</strong> if you can't do stateless requests.</p> <p>Final word: creating new contexts has a very small overhead, and it won't lead to performance issues 99% of the time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload