title: How to use spatial type with Entity Framework code-first without referencing Entity Framework
body: <p>I have an entity with some spatial data... I am using <code>DbGeography</code> and <code>DbGeometry</code> referenced in the <code>System.Data.Entity</code> assembly... </p>
  
  <p>I am not using that one referenced in <code>EntityFramework.dll</code> because I have a layered solution and I do not want to reference Entity Framework everywhere in my solution, but just inside the DAL...</p>
  
  <p>When I try to add a new migration I get the following error:</p>
  
  <blockquote>
    <p>EntityType 'DbGeometry' has no key defined. Define the key for this EntityType.</p>
  </blockquote>
  
  <p>So I tried to replace the <code>DbGeometry</code> property with a string <code>OnModelCreating</code> I have tried to write the following code:</p>
  
  <pre><code>modelBuilder.Entity&lt;AddressInfo&gt;()
      .Property(s =&gt; s.GeometryLocation)
      .HasColumnType("geometry");
  </code></pre>
  
  <p>But In this case I receive the error that the String data type is not compatible with the <code>DbGeometry</code> data type... </p>
  
  <p>Does anyone have any idea to solve this problem? Does anyone know which data type is compatible with <code>DbGeometry</code> data type? </p>
  
  <p>Thank you</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/19551142/entitytype-dbgeography-has-no-key-defined">EntityType 'DbGeography' has no key defined</a> does not solve my problem.. At the end, the author of the post says that </p>
  
  <blockquote>
    <p>[He] literally had to add a reference to Entity Framework in [his] model</p>
  </blockquote>
  
  <p>This is exactly what I want to avoid...</p>
  
  <p>Ryan also says that</p>
  
  <blockquote>
    <p>I think it may be fixable with a clever data configuration map though, I'll be playing with it and will update if I run across any workable techniques</p>
  </blockquote>
  
  <p>Any idea how to fix it? 
  Which could be a compatible data type to replace DbGeometry?</p>