Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my experience this code is not good, because you lose the capacity to navigate relationships through navigation properties. </p> <pre><code>public List&lt;Articles&gt; getArticles( ){ using (var db = new ArticleNetEntities()) { articles = db.Articles.Where(something).ToList(); } } </code></pre> <p>Using this approach you can't use the following code because a.Members is always null( db context is close and cant get data automatically). </p> <pre><code>var articles = Data.getArticles(); foreach( var a in articles ) { if( a.Members.any(p=&gt;p.Name=="miki") ) { ... } else { ... } } } </code></pre> <p>Using only a global db context is a bad idea because you must use a delete changes function</p> <p>in a point of your application yo do this but don't save changes and close the window</p> <pre><code>var article= globalcontext.getArticleByID(10); article.Approved=true; </code></pre> <p>then in another point of application you make some operation and save</p> <pre><code>//..... something globalcontext.saveChanges(); </code></pre> <p>in this case previous article approved property is set to modified by entity framework. When you save, approved is set true!!! </p> <p>Best approach for me is use 1 context per class You can pass context to another external method if you need</p> <pre><code>class EditArticle { private DbEntities de; private currentAricle; public EditArticle() { de = new DbEntities; //inizialize on new istance } loadArticleToEdit(Articele a){ // a is from another context currentArticle= de.Article.Single(p=&gt;p.IdArticle==a.IdArticle){ } private saveChanges(){ ... pe.saveChanges(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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