I have this sample code:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Models;
namespace MySampleNamespace
{
Depending on your .Net version you are using. Microsoft.EntityFrameworkCore.Tools.DotNet
only supports .NetStandard >= 2.0.
If your .Net version is 4.6.1, update Microsoft.EntityFrameworkCore
to 2.0.0-preview1-final, along with related EntityFramework DLLs, then close Visual Studio 2017 and re-open.
Ensure that the correct project is selected in the "Default Project" dropdown, and then type the command below :
install-package microsoft.entityframeworkcore.sqlserver
Ivan & Mardoxx are correct.
I tried to just install Microsoft.EntityFrameworkCore.Tools
then got this error:
Detected package downgrade: Microsoft.EntityFrameworkCore from 2.1.4 to 2.1.1. Reference the package directly from the project to select a different version. -> Microsoft.EntityFrameworkCore.Tools 2.1.4 -> Microsoft.EntityFrameworkCore.Design 2.1.4 -> Microsoft.EntityFrameworkCore.Relational 2.1.4 -> Microsoft.EntityFrameworkCore (>= 2.1.4) -> Microsoft.EntityFrameworkCore (>= 2.1.1)
ToTable
, unknown if this is even neededMicrosoft.EntityFrameworkCore.Relational
and it now resolvesInstalling Microsoft.EntityFrameworkCore.Relational
is the correct solution, as Ivan says.
You should add the nuget package Microsoft.EntityFrameworkCore.SqlServer
, since this is a Microsoft SQL method.
For EFCore 3.1 I needed to use this in my DB context:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
foreach (IMutableEntityType entity in modelBuilder.Model.GetEntityTypes())
{
entity.SetTableName("WS_" + entity.GetTableName());
}
}
No additional Nuget package was required.