I'm following the Pluralsight Course by Julie Lerman -- EntityFramework Core 2: Getting Started
. In this course, she has 3 projects. The first two Data
and Domain
are based on the .NET Standard library. The third project Web
is a .NET Core Web Application.
I've followed this structure. In Data
I added one POCO class called Client.
In Domain
I added one class called TestDbContext like so:
public class TestDbContext : DbContext
{
public DbSet<Client> Clients { get; set; }
public TestDbContext(DbContextOptions<TestDbContext> options) : base(options)
{
}
}
Following her example, I did the following in the Startup.cs of my Web
project to inject the provider and connection string into the DbContext.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<TestDbContext>(options =>
{
options.UseSqlServer(Configuration.GetConnectionString("TestConnection"));
});
}
Lastly, I attempt to add a migration to this context. I have the Web
project set as the startup project. From the Package Manager Console, I type add-migration initial
.
I then get the following error: The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can.
In Julie's video, this all worked for her and the migration package was created. However, for me -- just the error. Any clues as to what may be going on?
Check packages version of your project in '.csproj' file. Previously I have the same problem for version mitch match of AspNet Core and EntityFramework Core (I guess). Making those same works for me fine. Found solution Here
For me Now.
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0-rc1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0-rc1-final" PrivateAssets="All" />
Add 3 packages with same version from nuget package manager
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.2" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With