title: Mapping composite types from postgresql to ef core
body: <p>I defined the following <em>composite type</em> in my postgre db:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TYPE foobar AS
  (
     foo NUMERIC,
     bar NUMERIC
  );
  </code></pre>
  
  <p>I have created a struct with the same properties:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public struct FooBar
  {
     public decimal Foo { get; set; }
     public decimal Bar { get; set; }
  }
  </code></pre>
  
  <p>And now I would like to use FooBar as such in an entity:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class FooyaEntity
  {
     public Guid Id { get; set; }
     public string Name { get; set; }
     public FooBar FooBar { get; set; }
  }
  </code></pre>
  
  <p>How would I configure ef core to map these properly? Currently when trying to add something it will yield the following error:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The property 'Test.FooBar' could not be mapped, because it is of type 'FooBar' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.</p>
  </blockquote>
  
  <p>Also the <a href="https://www.npgsql.org/doc/types/enums_and_composites.html" rel="nofollow noreferrer">documentation for npgsql</a> shows working examples without ef core.</p>