title: Mapping a Domain Model to the database with EF Fluent API
body: <p>Below is the <strong>Project</strong> code-first class mapped directly to the database through the Entity Framework 6 Fluent API:</p>
  
  <pre><code>public class Project
  {
      public Project()
      {}
  
      public int ProjectId { get; set; }
  
      public string Name { get; set; }
  
      public bool IsActive { get; set; }
  
      public ICollection&lt;ProjectVersion&gt; ProjectVersions { get; set; }
  }
  </code></pre>
  
  <p>Anemic models in Domain-Driven Design are an anti-pattern.  I want to use this same class in my <strong>domain model</strong> instead of creating a separate <code>Project</code> domain class and having to perform complicated mapping between the two in the repository (and with the hundreds of other models we have).  </p>
  
  <p>This is how <code>Project</code> would look as a domain model class:</p>
  
  <pre><code>public class Project
  {
      private readonly List&lt;ProjectVersion&gt; projectVersions;
  
      public Project(string name, string description)
      {
          Name = name;
          Description = description;
          projectVersions = new List&lt;ProjectVersion&gt;();
      }
  
      public int ProjectId { get; private set; }
  
      public string Name { get; set; }
  
      public bool IsActive { get; private set; }
  
      public IEnumerable&lt;ProjectVersion&gt; ProjectVersions 
      { 
          get
          {
              return projectVersions;
          }
      }
  
      public void AddVersion(ProjectVersion version)
      {
          projectVersions.Add(version);
      }
  }
  </code></pre>
  
  <p><a href="http://entityframework.codeplex.com/wikipage?title=Design%20Meeting%20Notes%20-%20February%2020,%202013" rel="nofollow">From what I have read</a>, I am able to map to a private fields with EF's Fluent API.</p>
  
  <p><strong>Are there any any shortcomings here?  Am I taking an unnecessary shortcut?</strong></p>
  
  <p>The only problem I can forsee is when a business domain model would essentially consist of data from two or more data entities.</p>