title: Entity Framework 6 with an Immutable Class
body: <p>I have a <code>Point</code> class:</p>
  
  <pre><code>// My immutable Point class
  public class Point
  {
      private readonly Distance _x;
      private readonly Distance _y;
      private readonly Distance _z;
  
      public Distance X
      {
          get { return _x; }
      }
  
      public Distance Y
      {
          get { return _x; }
      }
  
      public Distance Z
      {
          get { return _x; }
      }
  
      // Ok, so this isn't immutable... but it's purely for EF
      public int DatabaseId { get; set; }
  
      public Point(Distance x, Distance y, Distance z)
      {
          _x = x;
          _y = y;
          _z = z;
      }
  }
  </code></pre>
  
  <p>(<code>Distance</code> is a custom class that stores a unit and a value.)</p>
  
  <p>That's great. We love immutability. But Entity Framework won't recognize that I need to put X, Y, and Z in the database because they don't have setters. And they shouldn't, because this is an immutable class. There shouldn't even be a <code>private set</code>. </p>
  
  <p>I have this code building my model:</p>
  
  <pre><code>    modelBuilder.Entity&lt;Point&gt;()
          .HasKey(point =&gt; point.DatabaseId);
  </code></pre>
  
  <p>Is there any way to preserve the true immutability of this class but also make it so that EF6 can access and store these values?</p>