Tag: ef migrations

字符串参数’migrationId’不能为空

如果这已经得到回答,请提前道歉,但我诚实地深挖并找不到与此错误有关的任何内容。 简而言之,我无法使用ASP.NET Core 1.1.2项目中的代码对我的数据库进行任何更新。 这是一个例外,因为它错过了一个我认为不与PMC有关的论点。 使用“更新数据库”时出现错误消息: 用于交叉检查Google的文字;-) System.ArgumentException: The string argument ‘migrationId’ cannot be empty. at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName) at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations() at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_1.b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) The string argument ‘migrationId’ cannot be empty. Migrations文件夹与我的’_EFMigrationsHistory’表相同(忽略计划更新的上次迁移): 我甚至已经删除了迁移文件夹和’_EFMigrationsHistory’表并再次启动,这表示同样的错误。 我也打算测试’v2.0.0-preview2-final’以防它是一个bug,但遗憾的是我的VS版只需要发布版本,显然你需要15.3。 版本信息: Visual Studio Enterprise 2017 – 15.2(26430.16)发布 entity framework核心v1.1.2 ASP.NET […]

无法将值NULL插入“Discriminator”AspNetUsers表列中

代码首次迁移后,使用该寄存器添加用户将失败: 无法将值NULL插入“Discriminator”列,表’aspnet-BSF2013-20130918101120.dbo.AspNetUsers’; 列不允许空值。 创建用户代码是项目模板生成的默认代码(Vs2013,带有EF5的MVC项目) 在成功迁移之前,注册代码有效,因此我猜测会员资格已被EF更改。

在entity framework迁移期间读取数据库(选择查询)

我知道我可以使用Sql方法在迁移过程中更新数据,它对于可以在纯SQL中表达的简单事物非常有用。 我也知道我可以使用Seed方法,但这会感觉像是一个黑客(我想写的代码必须执行一次,执行迁移时)。 在我目前的情况下,我需要从列中删除HTML标记,并将其写入迁移中添加的新列。 我已经有一个C#方法就是这么做的。 我想要做的是迭代C#中的每一行,并为每一行生成一个SQL语句,该行将使用相应的HTML条带化文本更新该行。 更一般地说,我认为在迁移过程中能够在C#中读取数据库在很多情况下都很方便。 在迁移事务中这样做是完美的,但为此我需要检索Entity Framework内部用于迁移的SQL连接。 到目前为止,我发现无法执行返回结果的SQL查询。 这可能吗?

如何将参数传递给DbMigration.Sql()方法

使用entity framework迁移时, DbMigration基类具有一个Sql方法,该方法接受匿名对象中的参数 我不能为我的生活弄清楚如何使用它。 Sql(@” UPDATE dbo.SlideSets SET Name = @Name, “, false, new { Name = “Foo” } ); 导致错误 System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable “@Name” 这句话的正确语法是什么?

Web Api 2.2 – 类库项目中的代码优先迁移

我在myVS 2015解决方案中有两个项目。 项目A. Web Api 2.2项目 主项目,其中定义了DBContext类和连接字符串(在web.config文件中) 项目B. class级图书馆计划 项目A作为参考添加 模型和控制器定义 模型inheritance了一个Project A类 创建了一个DBContext类,它从项目AinheritanceDBContext。 public DbSet Planets {get; 组; } 我对上述项目结构背后的想法是: 在项目变大时降低复杂性 使其不那么复杂并增加可读性 在项目A中制作身份validation和授权逻辑 我必须在项目B中实现以下内容: 需要从项目A共享/访问连接字符串 需要先运行代码迁移。 需要知道在将应用程序部署到prod时如何运行代码首次迁移? 问题: 我已启用代码首次迁移并更新了数据库。 我运行没有任何问题,但它没有运行在项目A的web.config中配置的数据库。相反,它添加自己的本地数据库。 我是否应该在项目B中指定连接字符串。 如果是,作为一个类库,我该如何添加配置文件?

如何在ASP.NET Core 1中使用EF6

我创建了一个ASP.NET Core 1项目并使用.Net Core 1.0框架。 并希望使用Entity Framework 6 。 我按照这个教程https://docs.efproject.net/en/latest/platforms/aspnetcore/new-db.html ,当我尝试使用语句进行迁移时: PM> Add-Migration MyFirstMigration 然后它告诉我: The EntityFramework package is not installed on project ‘IndustryCloud’. 可以在ASP.NET Core 1中使用EF6吗?

EntityFramework Npgsql DbConfiguration不起作用

我试图用Npgsql配置EntityFramework,首先是代码。 EntityFramework 6.1.3 Npgsql 3.0.5 现在,我想通过类设置自定义配置,让我们看看: public class DbConfig : DbConfiguration { public DbConfig() { SetProviderFactory(“Npgsql”, Npgsql.NpgsqlFactory.Instance); SetProviderServices(“Npgsql”, provider: NpgsqlServices.Instance); SetDefaultConnectionFactory(new NpgsqlConnectionFactory()); } } 和我的上下文类: [DbConfigurationType(typeof(DbConfig))] public class Db: DbContext { public virtual DbSet Products {get;set;} public Db(DbConnection Connection): base(Connection, true) { } public Db(): base() { } public Db(string connectionString): base(connectionString) { } protected […]

C# – 外键引用无效表 – 基本迁移无效

试图用C#创建我的第一个项目。 然而,到目前为止,它非常令人沮丧。 这是一个我无法解决的问题,因为我没有看到任何错误。 我正试图在我的数据库中进行简单的迁移。 用户迁移文件 public override void Up() { CreateTable( “dbo.Users”, c => new { user_id = c.Int(nullable: false, identity: true), first_name = c.String(), last_name = c.String(), email = c.String(), role = c.String(), }) .PrimaryKey(t => t.user_id); } 位置迁移文件 public override void Up() { CreateTable( “dbo.Locations”, c => new { loc_id = c.Int(nullable: false, […]

entity framework代码优先迁移的例外情况

我在使用Entity Framework 4.3的Code First Migrations时遇到了几个未处理的exception。 数据库上下文: public class MyAppContext : DbContext { public DbSet Branches { get; set; } public MyAppContext() { } } 实体: public class Branch : IEntity { public Guid Id { get; set; } public string Name { get; set; } public string Description { get; set; } public bool Active […]

无法在表上创建多个聚簇索引

键入update-database后出现以下错误: 无法在表’dbo.AppUsers’上创建多个聚簇索引。 删除现有的聚簇索引“PK_dbo.AppUsers”,然后再创建另一个。 我正在开发Azure移动服务。 我有三种数据模型: public class AppUser : EntityData { public string Username { get; set; } public virtual ICollection userRatings { get; set; } } public class PlaceItem : EntityData { public string PlaceName { get; set; } public int Group { get; set; } public string XCoordinate { get; set; } public […]