此平台不支持LocalDB

时间:2017-08-24 11:49:37

标签: 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.

这是我的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");
    }

}

你知道它可能是什么原因吗?

3 个答案:

答案 0 :(得分:7)

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

答案 1 :(得分:0)

从Windows机器切换到MacBook Pro时出现此问题。正如其他人指出的那样,LocalDB适用于SQL Server Express Edition。

要解决此问题,您需要安装SQL Server并使用localhost代替LocalDB。

答案 2 :(得分:-2)

需要像这样设置sql服务器:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "ConnectionStrings": {
    "WebAppContext": "Server=host_name;Database=database_name;MultipleActiveResultSets=true;User id=login;Password=password;"
  }
}