ef-migrations

No context type was found in the assembly EF6

大兔子大兔子 提交于 2019-12-12 16:36:42
问题 I'm working on a nopCommerce based project. In order to update custom entity I want to enable EF migrations. So I run following command: Enable-Migrations -StartUpProjectName nop.web -ContextProjectName Nop.Plugin.Payments.Deposit -verbose and get the error: Using StartUp project 'Nop.Web'. System.Data.Entity.Migrations.Infrastructure.MigrationsException: No context type was found in the assembly 'Nop.Plugin.Payments.Deposit'. at System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType,

Could not load assembly Microsoft.EntityFrameworkCore.Design when running Add-Migration

耗尽温柔 提交于 2019-12-12 09:42:54
问题 I have created a Class Library project with the following .csproj: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" /> <PackageReference Include="Microsoft

SetExecutionStrategy to SqlAzureExecutionStrategy with DbMigrationsConfiguration?

谁都会走 提交于 2019-12-12 09:34:13
问题 I saw a post today about implementing SqlAzureExecutionStrategy: http://romiller.com/tag/sqlazureexecutionstrategy/ However, all examples I can find of this use a Configuration that inherits from DbConfiguration. My project is using EF6 Code First Migrations, and the Configuration it created inherits from DbMigrationsConfiguration. This class doesn't contain a definition for SetExecutionStrategy, and I can find no examples that actually combine SqlAzureExecutionStrategy (or any

Execute Code First Migrations on Azure with Remote Connection String

爷,独闯天下 提交于 2019-12-12 09:18:08
问题 I am publishing an Azure Web App, and I'm running into a strange issue executing code first migrations. The remote connection string for this database is working just fine if I do not check "Execute Code First Migrations". However, if I check the box, a strange connection string with a curious misspelling, "ConnetionString", gets injected into the remote web.config: <add name="DbContext_DatabasePublish" connectionString="DbContext_DatabasePublish.ConnetionString" providerName="System.Data

Entity Framework - Seed AddOrUpdate with multi column index as identifier

让人想犯罪 __ 提交于 2019-12-12 08:28:52
问题 I am trying to seed a database using the context.AddOrUpdate method, but the problem is that I need to make the inserted data unique based on a multi column index. [Table("climbing_grades")] public class ClimbingGrade : EntityBase { /// <summary> /// The name of the climbing grade, e.g.: 7a, VII, etc. /// </summary> [Index("IX_Name_GradeType", 1, IsUnique = true)] public string Name { get; set; } /// <summary> /// Tries to display the average difficulty of the described grade. /// Matching

How to avoid recreate an existing database using automatic Code First Migration

本秂侑毒 提交于 2019-12-12 04:56:30
问题 I am using EF6, and having an issue with database automatic migration. The database exists, and there is no schema nor data changes in the db. But for some strange reason, the application seems to trying to re-create an existing table in the db on machine reboot. And therefore cause errors. My questions are: Why there will be automatic db migration when there is no db schema change? What triggered it? How to fix it. I use Include method to load entities like this, and the error occurs when I

Unable to implement IDbContextFactory for use with Entity Framework data migrations

折月煮酒 提交于 2019-12-12 04:38:11
问题 Tried to implement IDbContextFactory as follows. And got the following error at lines return Create(options.ContentRootPath, options.EnvironmentName); and var optionsBuilder = new DbContextOptionsBuilder<MyProjContext>(); when running following PM command PM> add-migration MyMigration -context MyProjContext Error An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time

Multiple identity columns specified for table exception [duplicate]

二次信任 提交于 2019-12-12 03:55:48
问题 This question already has answers here : Cant remove identity attribute from PK (2 answers) Closed 3 years ago . I have this initial migration: namespace DataAccess.Migrations { using System.Data.Entity.Migrations; public partial class init : DbMigration { public override void Up() { CreateTable( "dbo.SchoolclassCodes", c => new { Schoolclass = c.Int(nullable: false, identity: true), Type = c.String(), }) .PrimaryKey(t => t.Schoolclass); } public override void Down() { DropTable("dbo

EntityFramework core model relationship issue while doing Add-Migration

核能气质少年 提交于 2019-12-12 03:53:30
问题 I am facing an EntityFramework core model relation issue while doing migration using Package Manager Console in a asp.net core project. Getting below error while adding migration "Add-Migration". Unable to determine the relationship represented by navigation property 'College.Users' of type 'ICollection'. Either manually configure the relationship, or ignore this property from the model. Full Error System.InvalidOperationException: Unable to determine the relationship represented by

Entity Framework Initializer - seed database

左心房为你撑大大i 提交于 2019-12-12 02:39:34
问题 I'm using Entity Framework with code first migrations. I want to seed my database after creation(I'm using creatIfNotExist). Is it possible to combine migrations with initializer that inherit from creatIfNotExist? my code: static class Program { static void Main() { using (var db = new myDbContext()) { db.Database.CreateIfNotExists(); } } } public sealed class Configuration : DbMigrationsConfiguration<Core.Models.SpanTesterContainer> { public Configuration() { AutomaticMigrationsEnabled =