title: The entity type 'stream' requires a primary key to be defined. .Net Core 2.1
body: <p>I'm Using .NET Core 2.1.1 with Entity Framework Core 2.1.1, and I have the following Entity:</p>
  
  <h3>Some Entity</h3>
  
  <pre><code>using System;
  using System.ComponentModel.DataAnnotations;
  using System.IO;
  
  namespace MyWebApp.Models
  {
      public class Certificate
      {
          [Key]
          public int Id { get; set; }
  
          public DateTime CreatedAt { get; set; }
  
          public DateTime RequestedAt { get; set; }
  
          public Stream FileStream { get; set; }
      }
  }
  </code></pre>
  
  <p>Which represents a Certificate object where I plan to store the FileStream of a PDF file, using the last property of course. But When I try either to run a Migration using EF Core's Package Manager console command <code>Add-Migration Foo</code>, or when I try to run the project using an in-memory DataBase, I get the following errors:</p>
  
  <blockquote>
    <h3>When trying to add a Role</h3>
    
    <p>The entity type 'stream' requires a primary key to be defined.</p>
  </blockquote>
  
  <p>It only happens when the last property (FileStream) is present in the Entity, if I remove it works fine. I've searched other related questions, and most of them point to either:</p>
  
  <ul>
  <li>The primary key is not being recognized by EF because of naming conventions.</li>
  <li>A composite Key must be explicitly defined using the Fluent API.</li>
  <li>Just place a <code>[Key]</code> attribute before the primary key property.</li>
  </ul>
  
  <p>I've also tried to define the primary key using the Fluent API:</p>
  
  <h3>Here is my DbContext:</h3>
  
  <pre><code>using Microsoft.AspNetCore.Identity;
  using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  using Microsoft.EntityFrameworkCore;
  using System.IO;
  
  namespace MyWebbApp.Models
  {
  public class DbContext : IdentityDbContext&lt;IdentityUser&gt;
  {
      public DbSet&lt;ActionValue&gt; ActionValues { get; set; }
      public DbSet&lt;Certificate&gt; Certificates { get; set; }
      public DbSet&lt;VisualIVR&gt; VisualIVRs { get; set; }
      public DbSet&lt;SMSRequest&gt; SMSRequests { get; set; }
  
      public DbContext (DbContextOptions&lt;VysContext&gt; options)
          : base(options)
      {
  
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
  
          builder.Entity&lt;Certificate&gt;()
              .HasKey(c =&gt; c.Id);
      }
  }
  </code></pre>
  
  <h3>Here are the complete exception details</h3>
  
  <pre><code>System.AggregateException
    HResult=0x80131500
    Message=One or more errors occurred.
    Source=System.Private.CoreLib
    StackTrace:
     at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
     at System.Threading.Tasks.Task.Wait()
     at VysMiddleware.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory) in H:/MyApp/Startup.cs:line 84
  
  Inner Exception 1:
  AggregateException: One or more errors occurred.
  
  Inner Exception 2:
  InvalidOperationException: The entity type 'Stream' requires a primary key to be defined.
  </code></pre>
  
  <p>It seems to be something regarding the use of the <code>Stream</code> type, but I already have a primary key defined. Any suggestions?, Thanks so much for your help.</p>