title: How do I properly determine the relationships in Entity Framework from metadata classes?
body: <p>I'm currently using a package that collects API data (<a href="https://github.com/CrayonGroup/crayon-api-sdk" rel="nofollow noreferrer">Crayon API NuGet Package</a>), however, I'm struggling to implement this through Entity Framework. I am pulling Data from Crayon and I want to store it into a database, the code is fine, it's just the entity framework part that isn't working as I want it to. When I run the migrations I get this error :</p>
  <p><em>&quot;Unable to determine the relationship represented by navigation 'BillingStatement.TotalSalesPrice' of type 'Price'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.&quot;</em></p>
  <p>So by the looks of this error I need to configure the relationships, but I'm not sure how to do that through metadata, since the API data and classes are set in the package (metadata). But here is the Entity Framework model I'm using.</p>
  <pre><code>public class CrayonDbContext : DbContext
      {
          private const string connectionString = @&quot;myserver&quot;;
  
          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
          {
              optionsBuilder.UseSqlServer(connectionString);
          }
  
          public DbSet&lt;BillingStatement&gt; BillingStatements { get; set; }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
  
              modelBuilder.Entity&lt;AddressData&gt;().HasNoKey();
              modelBuilder.Entity&lt;Price&gt;().HasNoKey();
          }
      }
  </code></pre>
  <p>Here is the BillingStatement class from the metadata that it's using.</p>
  <pre><code>namespace Crayon.Api.Sdk.Domain.Csp
  {
      public class BillingStatement
      {
          public BillingStatement();
  
          public int Id { get; set; }
          public Price TotalSalesPrice { get; set; }
          public ObjectReference InvoiceProfile { get; set; }
          public ObjectReference Organization { get; set; }
          public DateTimeOffset StartDate { get; set; }
          public DateTimeOffset EndDate { get; set; }
          public ProvisionType ProvisionType { get; set; }
      }
  }
  </code></pre>
  <p>Now here are the referenced classes from the previously shown billing statement class.</p>
  <pre><code>public class Price
  {
      public Price();
  
      public decimal Value { get; set; }
      public string CurrencyCode { get; set; }
  }
  
  public class ObjectReference
  {
      public ObjectReference();
  
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  public enum ProvisionType
  {
      None = 0,
      Seat = 1,
      Usage = 2,
      OneTime = 3,
      Crayon = 4,
      AzureMarketplace = 5
  }
  </code></pre>
  <p>I'm aware that when Normalization is involved it starts to become a lot more complicated. What would I do with this? How would I configure the relationships? Is there any good source material that helps with metadata classes where I can scaffold the tables and store the data as intended?</p>
  <p>Any help here would greatly be appreciated.</p>