@Tseng, thanks! Here are the explicit instructions.
Edit project file:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup> </Project>
Then add the factory design:
public class DesignTimeActivitiesDbContextFactory : IDesignTimeDbContextFactory<ActivitiesDbContext> { public ActivitiesDbContext CreateDbContext(string[] args) { DbContextOptionsBuilder<ActivitiesDbContext> builder = new DbContextOptionsBuilder<ActivitiesDbContext>(); var context = new ActivitiesDbContext( builder .UseSqlServer("Data Source=(local);Initial Catalog=Activities;Integrated Security=False;User ID=user;Password=pw;Connect Timeout=30;Encrypt=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;") .Options); return context; } }
Then build.
Then open the command line, go to the project folder and run:
dotnet ef migrations add InitialCreate
Now there should be an automatically generated migration folder. Love it!
sikemullivan
source share