title: The required column 'CustomerId' was not present in the results of a 'FromSql' operation
body: <p>The error message is clear:</p>
  
  <blockquote>
    <p>'The required column 'CustomerId' was not present in the results of a
    'FromSql' operation'</p>
  </blockquote>
  
  <p>But somehow I didn't really expect a CustomerId?</p>
  
  <p>The error happens here: </p>
  
  <pre><code>contacts = db.Contacts.FromSql("SIP_API_MONDIA_Contacts_sel").ToList();
  addresses = db.Addresses.FromSql("SIP_API_MONDIA_Address_sel").ToList();
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>  public IList&lt;Customer&gt; GetAllCustomers()
          {
              //Initialize the objects
              IList&lt;Customer&gt; customers = null;
              IList&lt;Contacts&gt; contacts = null;
              IList&lt;Addresses&gt; addresses = null;
  
              //Fetch the data from stored procedures
              customers = db.Customers.FromSql("SomeProcName").ToList();
              contacts = db.Contacts.FromSql("SomeProcName").ToList();
              addresses = db.Addresses.FromSql("SomeProcName").ToList();
  
              //Loop through customers and add the contact and addresses when required
              foreach(var item in customers)
              {
                  item.Contacts = contacts.Where(x =&gt; x.Customer == item.Id).ToList();
                  item.Addresses = addresses.Where(x =&gt; x.Customer == item.Id).ToList();
              }
              return customers;
          }
  </code></pre>
  
  <p>The model:</p>
  
  <pre><code>public class Customer
      {
          public Guid Id { get; set; }
          public string Code { get; set; }
          public string Name { get; set; }
          public string VatCode { get; set; }
          public string ChamberOfCommerceCode { get; set; }
          public DateTime Modified { get; set; }
          public DateTime Created { get; set; }
          public string LanguageCode { get; set; }
          public decimal Discount { get; set; }
          public string CustomerManager { get; set; }
          public Guid PriceList { get; set; }
          public Guid PaymentCondition { get; set; }
         // public bool VatLiable { get; set; }
          public bool IsBlocked { get; set; }
          public bool IsProspect { get; set; }
          public bool IsSuspect { get; set; }
          public string Website { get; set; }
          public string DashboardUrl { get; set; }
          public string Email { get; set; }
          public string Phone { get; set; }
          public string Fax { get; set; }
          //     public ICollection&lt;FreeFields&gt; FreeFields { get; set; }
          //      public Dictionary&lt;string, string&gt; UknownElements { get; set; }
          public ICollection&lt;Contacts&gt; Contacts { get; set; }
          public ICollection&lt;Addresses&gt; Addresses { get; set; }
      }
  
      public class FreeFields
      {
          public string Key { get; set; }
          public string Value { get; set; }
      }
  
      public class Contacts
      {
          public Guid Id { get; set; }
          public string FirstName { get; set; }
          public string MiddleName { get; set; }
          public string LastName { get; set; }
          public string Initials { get; set; }
          public string Function { get; set; }    
          public Guid Customer { get; set; }
          public string Email { get; set; }
          public string Phone { get; set; }
          public string Mobile { get; set; }
          public string LanguageCode { get; set; }
          public bool IsMainContact { get; set; }
          public string Gender { get; set; }
          public string Username { get; set; }
      }
      public class Addresses
      {
          public Guid Id { get; set; }
          public string AddressLine1 { get; set; }
          public string AddressLine2 { get; set; }
          public string AddressLine3 { get; set; }
          public string Postcode { get; set; }
          public string City { get; set; }
          public string Country { get; set; }
          public string CountryCode { get; set; }
          public string Type { get; set; }
          public Guid Customer { get; set; }// This Property should be GUID instead of String..
          public bool IsMainAddress { get; set; }
          public string Route { get; set; }
          public string State { get; set; }
      }
  </code></pre>
  
  <p>I am not entirely sure what the error means with 'CustomerId'
  The stored procedures return the 100% exact value of the models.</p>
  
  <p><strong>Edit in order to add print scrn of the sql resultset &amp;&amp; DbContext:</strong></p>
  
  <pre><code>public class IsahContext : DbContext
      {
          public  IsahContext()
          {
  
          }
  
          public IsahContext(DbContextOptions&lt;IsahContext&gt; options)
              : base(options)
          {
          }
  
          protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
          {
              if (!optionsBuilder.IsConfigured)
              {
                  optionsBuilder.UseSqlServer(Setting.ConnectionString);
              }
          }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
          }
  
          //Entities will come here 
          public DbSet&lt;Customer&gt; Customers { get; set; }
          public DbSet&lt;Addresses&gt; Addresses { get; set; }
          public DbSet&lt;Contacts&gt; Contacts { get; set; }
  
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/B2eFE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B2eFE.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/XefJU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XefJU.png" alt="enter image description here"></a></p>