ef-migrations

Entity Framework Data Annotations equivalent of .WillCascadeOnDelete(false);

青春壹個敷衍的年華 提交于 2019-12-09 00:25:44
问题 I'm currently using EF Code First 4.3 with migrations enabled, but automatic migrations disabled. My question is simple, is there a data annotations equivalent of the model configuration .WillCascadeOnDelete(false) I would like to decorate my class so that the foreign key relationships do NOT trigger a cascading delete. Code sample: public class Container { public int ContainerID { get; set; } public string Name { get; set; } public virtual ICollection<Output> Outputs { get; set; } } public

Composite Key EF Core getting error when using Fluent Api

不羁的心 提交于 2019-12-08 21:53:25
问题 So I have the following class in Entity Framework Core. I am trying to do a code first migration and can't for the life of me figure out how to make the fluent API for this work. public class Participants { public Activity Activity { get; set; } //Class with Id and Name of Activity public ApplicationUser Participant { get; set; } [Key] [Column(Order = 1)] public int ActivityId { get; set; } [Key] [Column(Order = 2)] public string ParticipantId { get; set; } } In EF6 I was able to do this in

EF Code First Migration throws StackOverflowException on Azure Web Role

和自甴很熟 提交于 2019-12-08 20:53:35
问题 The issue occurs when executing EF 6.1.2 code first migrations in an Azure Web Role (WS 2012 R2). The same migrations run fine locally, even if I point the connection string to the (Azure) Sql Database. The StackOverflowException is thrown by Entity Framework code, and the first line of ANY of my migrations doesn´t even get hit. I have tried running the migrations in three different ways: DbMigrator migrator = new DbMigrator(configuration); migrator.Update(); // Here the exception is thrown

Entity framework core, code first migration with data migration

允我心安 提交于 2019-12-08 20:38:22
问题 I am trying to use EF Core code first migrations to de-normalise an existing table. I have en existing table LoginEvent which data looks like this: ╔═════════════════════════════════════════════════╗ ║ LoginEvent ║ ╠════╦══════════╦═══════════╦════════════╦════════╣ ║ Id ║ VenueRef ║ VenueName ║ OccurredAt ║ UserId ║ ╠════╬══════════╬═══════════╬════════════╬════════╣ ║ 1 ║ ven01 ║ Venue 1 ║ 2018-01-29 ║ 5 ║ ╠════╬══════════╬═══════════╬════════════╬════════╣ ║ 2 ║ ven02 ║ Venue 2 ║ 2018-01

Migration: No DbContext was found in assembly

雨燕双飞 提交于 2019-12-08 20:38:21
问题 Using VS Community 2017. I have tried to create initial migration with error message saying: Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6. No DbContext was found in assembly 'Test_Project'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic. ... code in my dbcontext: protected override void OnModelCreating(DbModelBuilder mb) {

How to add the “Provider Name” in Connection String to the Context file?

血红的双手。 提交于 2019-12-08 16:12:10
问题 I am Using Entity Framework 5 Code-first approch. Here is my Context file : using IMS.Domain.Inventory; using IMS.Domain.Security; using IMS.Domain.StoredProcedures; using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.Objects; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IMS.Domain.DBContext { public class IMSDBContext : DbContext { public DbSet<ModuleAccounting> ModuleAccountings

How to pass parameters to DbMigration.Sql() Method

瘦欲@ 提交于 2019-12-08 15:58:42
问题 When using Entity Framework Migrations, the DbMigration base class has a Sql method which takes parameters in an anonymous object I cannot for the life of me figure out how to use it. Sql(@" UPDATE dbo.SlideSets SET Name = @Name, ", false, new { Name = "Foo" } ); Results in the error System.Data.SqlClient.SqlException (0x80131904): Must declare the scalar variable "@Name" What's the correct syntax of this statement? 回答1: The standard generator for MSSQL is doing nothing with the anonymous

EF Code First 5.0.rc Migrations doesn`t update Identity property

Deadly 提交于 2019-12-08 15:27:37
问题 Say, we are using EF Code First and we have this simple model: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Data.Entity; using System.Linq; using System.Web; namespace EFCodeFirstIdentityProblem.Models { public class CAddress { public int ID { get; set; } public string Street { get; set; } public string Building { get; set; } public virtual CUser User { get; set; } } public class CUser { public int ID { get; set; } public string

How to recreate migrations from scratch

我的梦境 提交于 2019-12-08 13:44:35
问题 I recently upgraded from EF6 alpha 1-3 to EF6 beta 1. This meant that I had to recreate all the migrations created using the alpha version. So I tried to roll back to a migration created using EF5. But I hit the error Introducing FOREIGN KEY constraint on table may cause cycles or multiple cascade paths . I figure this is because I had neglected to fix Down migrations when I was fixing Up migrations for exactly the same problem. (Should have read this before) Anyway, rather than try to fix it

No context type found in the assembly. ASP.NET MVC4

你离开我真会死。 提交于 2019-12-08 09:52:42
问题 Was following this tutorial here (wanted a database of customers instead of movies as per tutorial): http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-new-field-to-the-movie-model-and-table However when I attempt to run migrations commands the following error is encountered: "The context type 'MvcCustomer.Models.CustomerDbContext' was not found in the assembly 'MvcVault'." This is my customer model: using System; using System.Collections.Generic; using System