title: WebApi OData v4 ComlexType cannot have an EntityType
body: <p>We were using WebApi OData v<strong>3</strong> and had a couple <code>ComplexType</code> entities defined in the entity data model that contained <code>EntitySet</code> entities.</p>
  
  <p>When moving to OData v<strong>4</strong> and upon doing the <code>modelBulder.GetEdmModel()</code> step we get an InvalidOperationException "The complex type 'Foo' refers to the entity 'Bar' through the property 'Bar'."</p>
  
  <p>I look at the spec and see a thing called an "abstract entity type" that is a type that holds entity types. I don't see that in the WebApi OData code so I <em>hope</em> that all I have to do is declare an <code>EntityType</code> that has no key and I get one. </p>
  
  <p>No dice. Making my <code>Foo</code> type an <code>EntityType</code> (doing <code>modelBuilder.AddEntityType(typeof(Foo))</code> instead of <code>modelBuilder.AddComplexType(typeof(Foo))</code>) gives an InvalidOperationException "The entity 'Foo' does not have a key defined".</p>
  
  <p>Is there a entity-data-model clean way to use a <code>ComplexType</code> or an <code>EntityType</code>?</p>
  
  <p>One clean but painful solution would be to make even more classes that are essentially my entities renamed and added to the model as <code>ComplexType</code> so that I can return the data as a complex type (I would include casting operators from the entity types to the matching complex types so they could be used interchangeably in client code). Obviously, I don't want to go through this pain for something that worked fine before upgrading to OData v4.</p>
  
  <p>A much easier but non-clean way (and I have done this and it works) involves inserting an unused key into each now <code>EntityType</code> that used to be a <code>ComplexType</code> like this:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Gets or sets the not used "key" property
  /// &lt;/summary&gt;
  /// &lt;remarks&gt;
  /// OData v4 seems to have broken the ability of a complex type to hold 
  /// an entity type. In the spec, there is the notion of an abstract 
  /// entity type - an entity type that does not have a key. But, it 
  /// appears v4 doesn't support abstract entity types. Hence, this "key".
  /// &lt;/remarks&gt;
  [Key]
  public int NotUsed { get; set; }
  </code></pre>