c# - 此平台不支持 LocalDB

标签 c# database entity-framework .net-core .net-core-2.0

我正在尝试在 Ubuntu 17.04 上启动 .Net Core 2.0 应用程序。我之前在 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");
    }

}

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

最佳答案

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

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

这里是 Ubuntu 的安装脚本, Red Hat , 和 SUSE .

或者使用 Docker 镜像:

https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker

关于c# - 此平台不支持 LocalDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45860851/

相关文章:

c# - 免安装 C# 应用程序的局限性?

SQL从2个不相关的表中合并2个不相关的列

c# - EntityFramework 和 ReadOnlyCollection

c# - 从 Linq lambda 返回多个字段

c# - 从对象盒类型进行通用转换

c# - 如何在MySQL中插入日期

database - Postgres 中的脏读

php - echo 失败错误

c# - 在高负载 Web 应用程序中正确使用 Entity Framework

林克。如何查询列表中的列表?