ef-migrations

How to write an Edit Action

不羁的心 提交于 2020-01-06 19:40:55
问题 I am trying to come up with an edit action. See below for what i have so far. ViewModel: using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Web; using System.Web.Mvc; namespace GlobalUnitedSC.WebUI.Models { public sealed class CreateMensPlayerViewModel { //Player profile starts here [HiddenInput(DisplayValue=false)] public int MensTeamId { get; set; } [HiddenInput(DisplayValue = false)] public int PlayerId { get; set; }

Error Seeding Database? (MVC 4 Application, EF 5, Code-First)

孤人 提交于 2020-01-06 08:27:12
问题 I've successfully added a new migration in my project, but when I run update-database in Package Manager Console I receive: Error Seeding Privileges: An error occurred while updating the entries. See the inner exception for details. . Full Details: PM> update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending explicit migrations. Running Seed method. System.Exception: Error Seeding Privileges: An error occurred while updating the

No parameterless constructor defined for this object in asp.netcore migrations

北城以北 提交于 2020-01-06 06:19:06
问题 I am new to ASP.NET Core. learning new version of .NET Core 2.0 using VS Code. I got stuck while doing creating database using migration. First, it gives an exception of implementation of IDesignTimeDbContextFactory. After solving this, it still gives an exception of No parameterless constructor defined for this object Here's my code for DbContextClass: public VegaDbContext CreateDbContext(string[] args) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory

A network-related or instance-specific error occurred while establishing a connection to SQL Server while migration with asp.net core migration

被刻印的时光 ゝ 提交于 2020-01-06 06:09:07
问题 I, am using package manager console to perform the database migration. I used the following command Add-Migration init This command work perfectly and created the migration object as see in the below image Now I am using Update-Database command to create the database however I, am getting an error as shown below I have used the solution provide here and this question. However, this solution is not working for me from visual studio. I, am able to use the sql server from SSMS. This error is

EF code first migrations, DB generated guid keys

牧云@^-^@ 提交于 2020-01-06 04:26:05
问题 The question as a one liner How do I get EF to generate as part of a code first migration ALTER TABLE [DMS].[Forms] ADD CONSTRAINT [DF_DMS.Forms_Id] DEFAULT (newid()) FOR [Id] GO More detail of the problem I'm to build out a simple table to store information about forms, as it happens I already have this working for another table in my db but if I show you the code (see below) you'll realise the issue i'm hitting is more strange than it might seem ... First the working example entity: [Table(

add new column to database table dynamically

☆樱花仙子☆ 提交于 2020-01-06 02:30:09
问题 As EF Migration do provide a way to create new columns as part of migration like below public class AddRatingMig : DbMigration { public override void Up() { AddColumn("dbo.Movies", "Rating", c => c.String()); } public override void Down() { DropColumn("dbo.Movies", "Rating"); } } But I want to create a column as part of code and not thru migration. We are providing admins an option to capture more information about the users of the application. The facility to do that will be thru some

How to debug Entity Framework migration LoaderExceptions?

↘锁芯ラ 提交于 2020-01-06 01:54:28
问题 I'm trying to run update-database in an Entity Framework 5 project that runs on other machine. I downloaded the code, rebuilt the project and when I run update-database I get an error like this: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) at System.Reflection.RuntimeModule.GetTypes() at System.Reflection.Assembly

Adding properties to IdentityUser doesn't create the correct migration

流过昼夜 提交于 2020-01-05 07:45:21
问题 I've followed the tutorial here: Customizing profile information in ASP.NET Identity in VS 2013 templates And did exactly what's written there, except for that my new property is a string named 'TaxId'. Surprisingly, when I did the "Add-Migration" part, the migration file came up empty: namespace Mvc5Test.Migrations { using System; using System.Data.Entity.Migrations; public partial class TaxId : DbMigration { public override void Up() { } public override void Down() { } } } Any idea why did

How to generate code first migration script from a specific migration?

六月ゝ 毕业季﹏ 提交于 2020-01-05 03:36:12
问题 I have a production and a development database. Now I want to generate a sql script based on a specific migration. When I enter the line to generate the script I get this error: '201608121243147_AutomaticMigration' is not a valid migration. Explicit migrations must be used for both source and target when scripting the upgrade between them. The command I use is as follows: Update-Database -Script -SourceMigration:201608121243147_AutomaticMigration -TargetMigration:201608281101542

Entity Framework Data Migrations for Different Environments

元气小坏坏 提交于 2020-01-04 09:09:10
问题 There are some base data specific for Dev/Test/Prod environments. We are using now Entity Framework Migrations for all the environments but do not know how to specify migrations for particular environments in a way that we specify a migration to be executed only on Dev/Test/Prod. This could be accomplished in Fluent Migrator with Tag attributes. But what about Entity Framework? 回答1: When you say 'base data' I assume you mean Seeding each environment. Migrations provide a seeding mechanism for