Entity Framework Core

recipes

  • use an in memory db for tests

      public class MessagingDbContext : Microsoft.EntityFrameworkCore.DbContext { /* ... */ }
    
      return new MessagingDbContext(new DbContextOptionsBuilder<MessagingDbContext>().UseInMemoryDatabase(databaseName: DB_NAME).Options)
    
  • Fix $ dotnet ef database update returning No executable found matching command “dotnet-ef”. Modify csproj.

      <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1"/>
      <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
          <Version>1.0.0-*</Version>
      </DotNetCliToolReference>  
    
  • Generate migration from Powershell / Git Bash

      install-package entityframework.commands -pre
      dotnet ef migrations add "Initial" -o "Data\Migrations"
      dotnet ef database update