title: How to separate POCO layer from Entity Framework layer and still be able to add business logic to objects
body: <p><em>I've seen a lot of these types of questions on here but they are either unanswered, not quite the same question that I am asking or the detail I need.</em>  </p>
  
  <p>I have included a screenshot of my project below for a high-level reference view of things.</p>
  
  <ol>
  <li>In my "Sample" solution, I currently have a project called <code>Sample.Data.Model</code> that contains an edmx file of my database-first model.  </li>
  <li><strong><a href="http://blogs.msdn.com/b/adonet/archive/2010/01/25/walkthrough-poco-template-for-the-entity-framework.aspx" rel="nofollow noreferrer">Following the steps in this MSDN walkthrough,</a></strong> I then moved the auto-generated POCO classes into a separate project and called it <code>Sample.Data.Entities</code>. </li>
  <li>I then referenced the <code>Sample.Data.Entities</code> project in my <code>Sample.Data.Model</code> project and fixed all the usings so my project builds successfully.</li>
  <li>I will of course need to add to the POCO classes so I added a <code>PartialClasses</code> folder in the <code>Sample.Data.Entities</code> project for my partial classes.</li>
  </ol>
  
  <p>And then this is where I get lost.  In smaller (non n-tier projects) my edmx file and partial classes where in the same project so I could just add my class object related methods in my partial class files like this: </p>
  
  <pre><code>namespace Sample.Data.Entities
  {
      public partial class User
      {
          public string FullName 
          { 
              get 
              { 
                  return string.Format("{0} {1}", this.FirstName, this.LastName); 
              } 
          }
      }
  
      public User GetUser(int userID)
      {
          using (var dc = new ProntoEntities())
          {
              return (from u in dc.Users where u.ID == userID select u).SingleOrDefault();
          }
      }
  }
  </code></pre>
  
  <p>And then in MVC project I could just do something like this...</p>
  
  <pre><code>User user = new User();
  user = user.GetUser(1);
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>User user = new User();
  user.FirstName = "John";
  user.LastName = "Smith";
  user.Update();
  </code></pre>
  
  <p>However, I can't do that in this current setup because the partial classes know nothing about the Entities.</p>
  
  <p>So, my question is, where in my current setup do I put the "queries" for data?</p>
  
  <p>Also, if I'm going to make "ViewModels" for my MVC project, where should those go?  I would usually put those in the same project as my partial classes and edmx file as well.</p>
  
  <p><strong><a href="http://screencast.com/t/WTWCPfEz" rel="nofollow noreferrer">Click to view larger version of image below</a></strong></p>
  
  <p><img src="https://i.stack.imgur.com/3zUv4.png" alt="enter image description here"></p>