此平台不支持LocalDB

YTe*_*rle 13 c# database entity-framework .net-core .net-core-2.0

我正在尝试启动.Net Core 2.0应用程序Ubuntu 17.04.我以前在Windows 10上开发它并且运行良好.问题是,当我运行时,dotnet ef database update我得到下一个异常:

System.PlatformNotSupportedException: LocalDB is not supported on this Platform.
Run Code Online (Sandbox Code Playgroud)

这是我的DbContext:

public class NutritionContext : DbContext
{
    public DbSet<User> Users { get; set; }
    public DbSet<Meal> Meals { get; set; }
    public DbSet<Dish> Dishes { get; set; }
    public DbSet<Product> Products { get; set; }
    public DbSet<Plan> Plans { get; set; }
    public DbSet<MealDish> MealDishes { get; set; }
    public DbSet<Ingredient> Ingredients { get; set; }
    public DbSet<PlanDetail> PlanDetails { get; set; }
    public DbSet<UserPlan> UserPlans { get; set; }
    public DbSet<AuthUser> AuthUsers { get; set; }

    public NutritionContext()
    {
    }

    public NutritionContext(DbContextOptions options) : base(options)
    {           
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer(
            "Server=(localdb)\\mssqllocaldb;Database=NutritionDatabaseNew;Trusted_Connection=True;MultipleActiveResultSets=true");
    }

}
Run Code Online (Sandbox Code Playgroud)

你知道它的原因是什么吗?

Dav*_*oft 10

LocalDb是SQL Server Express Edition的打包机制,仅适用于Windows.在Ubuntu上,您可以安装SQL Server 2017.

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-overview

https://docs.microsoft.com/en-us/sql/linux/sample-unattended-install-ubuntu


Ben*_*Ben 7

我从 Windows 机器切换到 MacBook Pro 时遇到了这个问题。正如其他人指出的那样,LocalDB 适用于 SQL Server Express Edition(适用于 Windows)。

要解决此问题,您需要安装 SQL Server 并使用 localhost 而不是 LocalDB。