ef-migrations

The 'data source' keyword is not supported. (ASP.Net app, Entity-framework 5, Code first, migrations)

≯℡__Kan透↙ 提交于 2019-12-10 19:59:48
问题 I have an OData/WCF Data Services endpoint (ASP.Net site) that I would like to switch from using EF Code first datamodel with SQL Server 2012 as backend to EF Code first datamodel with LocalDB as backend - on our dev machines using Visual Studio 2012. Code is placed in TFS and we share the code between 5-6 developers. Existing unit tests run smoothly after switching to LocalDB. The config for the unit test project is this: <?xml version="1.0" encoding="utf-8"?> <configuration> <configSections

EF Code First Migrations creating extra foreign key

北战南征 提交于 2019-12-10 19:50:29
问题 I'm trying to create a Profile table to integrate with the Asp.Net Identity table: AspNetUsers . I'm using Code First Migrations with EF 6.0. Here is my User class: public class ApplicationUser : IdentityUser { public ApplicationUser() { } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } public UserStatus Status { get; set; } public virtual Profile Profile { get; set; } } Here is my Profile class: public class Profile { public int ID { get; set; }

Migrate database-first to code-first - switch from publish to migrations

≯℡__Kan透↙ 提交于 2019-12-10 17:57:24
问题 We need to migrate an existing project from database-first to code-first. Each environment (DEV, TEST, PROD) has a slightly different version of the database. The differences are the changes in DEV that may not have been pushed to TEST and PROD. -- We are using Entity Framework 6.1.3. We have a database project that deploys the database. The publish operation compares the database with the project and builds a script to change the database as needed. We have a models project with an edmx

New embedded Firebird, code first, EF6 project results in SerializationException

烈酒焚心 提交于 2019-12-10 17:39:24
问题 I'm trying to set up Firebird with EF6 as an embedded server for a simple app I'm writing but haven't been able to get it to work. I have a CLI project which is the app and the DAL project which is the DB. I added the NuGet packages to both and created a DbContext with a simple entity, and created an initial migration successfully, but when trying to run update-database to execute the migration I received this error in the Package Manager Console: System.Runtime.Serialization

How can Entity Framework Code First Create Index in Descendent order?

不羁岁月 提交于 2019-12-10 17:36:23
问题 In fluent API, we can specify an Index on a field: var indexAttr = new IndexAttribute("IX_EmployeeNumber") { IsClustered = true }; Property(c => c.EmployeeNumber) .HasColumnAnnotation("Index", new IndexAnnotation(indexAttr )) .HasMaxLength(8) .IsRequired(); After Add-Migration , we will get this CreateIndex statement: CreateIndex("dbo.Employees", "EmployeeNumber", clustered: true, name: "IX_EmployeeNumber"); After a Update-Database , we have a sql like this: CREATE CLUSTERED INDEX [IX

Change or rename a column name without losing data with Entity Framework Core 2.0

穿精又带淫゛_ 提交于 2019-12-10 17:06:12
问题 I realised that I had spelt one of my column headers incorrectly so I changed it in the model and created a new migration to update it into the database. All worked perfectly until I realised that what actually appeared to happen was a new column replaced the existing column and erased all the data. As it happens, as this was a tutorial database, it was no big deal and a work of a few minutes to put the data back. How/what do I do to update/rename a column without losing the data in it? Not

Entity Framework with multiple migrations and inheritance from base DbContexts within the same Database

自作多情 提交于 2019-12-10 16:44:33
问题 I'm building an extensible custom CMS solution where I have a parent DbContext named CmsDbContext with the entities for CMS tables, eg: Users table. CmsDbContext has automatic migrations enabled. I want allow the final user inherit from CmsDbContext in order to create custom extra tables/entities, by adding/mapping DbSet properties and custom POCO's. The Cms needs that his CmsDbContext get initialized in PreStart, before the initialization of derived DbContext. So far so good, when I

Alter Stored Procedure in DB Migration EF 6 Code First - how to pass through null as default for a parameter

浪尽此生 提交于 2019-12-10 16:28:58
问题 I am using an Empty Migration to update a stored procedure in my database. The stored procedure is a custom stored proc that was added in the intial creation of the database. I have discovered the 'AlterStoredProcedure' method in the DbMigration class and this works to update the stored procedure, however I have to pass through the parameters of the stored procedure and I want to set the default value of a boolean and some ints to null, but I can't seem to get this to work.

EF core migration failed: System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler

余生长醉 提交于 2019-12-10 16:22:54
问题 I made Entity Framework core migration first time to my average size project (about 100 tables) and now I am trying to do changes to the azure sql db with 'Update-Database' call in package manager console. I will get this error always: Exception message: Stack trace: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler

DbMigration.Sql method: can I use the “suppressTransaction” parameter safely?

爱⌒轻易说出口 提交于 2019-12-10 16:09:35
问题 When I want to create or alter stored procedures and views, I avoid the "should be the first statement in a batch file" error by putting the sql inside an EXEC statement like this: Sql(EXEC('Alter View dbo.Foos As etc')) This is all very well, but it does mean I have to escape apostrophes all the time. I recently realised that the DbMigration.Sql method takes a boolean parameter named suppressTransaction . It is described like this in the documentation: A value indicating if the SQL should be