ef-migrations

Ef core migrations in full .net project in VSTS

廉价感情. 提交于 2019-12-24 12:07:56
问题 I have created a .net core web app targeting the full .net framework I Have created a class library (.net framework) In this dll I have referenced ef core and created a context. Migrations work when I use the package manager. The Problem I am currently facing I need to be able to use migrations during a VSTS deployment. I have tried creating a powershell deployment script in VSTS to call dotnet-ef commands. This doesn't work, because I can't install Microsoft.EntityFrameworkCore.Tools.DotNet

EF Core - Unique constraint including navigation property not detected in migration

六眼飞鱼酱① 提交于 2019-12-24 12:05:20
问题 I am trying to apply a unique composite constraint, one of the parts of the constraint is a foreign key. The only way I can seem to make it work is to explicitly defined the foreign key in my domain class, which I want to avoid. Is this possible? The problem and the workaround applies to both HasAlternateKey and HasIndex . The solution builds fine, but the constraint is ignored when creating a migration until the shadow property is turned into a real property in the domain class. This does

`Only primitive types or enumeration are supported in this context` error whilst seeding ASP.NET MVC using AddOrUpdate match on multiple fields

巧了我就是萌 提交于 2019-12-24 11:08:13
问题 My first question on stackoverflow.com! Wish me luck explaining :) I am trying to seed a development database with some test data, requiring matching on two fields, and encountered the issue solved here How to seed data with AddOrUpdate with a complex key in EF 4.3 I get the Only primitive types or enumeration types are supported in this context. error as mentioned in the comments by lukyer. However, despite adding foreign key attributes, and required attributes to the properties in the model

Error in migrations in EFCore

↘锁芯ラ 提交于 2019-12-24 09:29:28
问题 When I run Add-Migration using Microsoft.EntityFrameworkCore.Tools 1.1.1, I get the following error: Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. Parameter name: startIndex" At line:1 char:1 + Add-Migration + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration The same stuff works perfect with version 1.1.0-preview4-final 回答1:

Adding a new relation to existing database using entity framework

。_饼干妹妹 提交于 2019-12-24 06:29:47
问题 Given a database with a table A. I want to create a table B and add a one-to-may relation between A and B with a required foreign key. For example suppose that have an existing table 'Users' and then we want to add 'Roles' to the existing users. The code first definition of those entities is as follows: public class User { public Id UserId { get; set; } public string Email { get; set; } public string UserName => Email; public Roles Role { get; set; } public int? RoleId { get; set; } } public

How do I use DotNet Migrations in .Net Core when my Model and Repository are in a class library?

喜欢而已 提交于 2019-12-24 04:26:05
问题 I am following this article/tutorial on how to make a generic repository for ASP.Net Core at: http://www.c-sharpcorner.com/article/generic-repository-pattern-in-asp-net-core/ When I download the code I am able to run the migrations and the project runs and works. But when I follow the directions and try to build from scratch, then when I get to the point where I have to run the migrations: Add-migration MyFirstMigration I get this error: C:\Tutorials\ASP.Net\Core\GenericRepository\FromScratch

EF Migration migrate to 0 call initial creates down

此生再无相见时 提交于 2019-12-24 02:31:50
问题 I'm trying to figure out the syntax to bring migrations down to an empty database as in call the down method on the inital create migration. Does anyone know the proper syntax to call the Down method in a migration something akin to this: Update-Database -StartupProjectName "Infrastructure.Data" -TargetMigration 0 回答1: update-database -startupproject someproject -targetmigration 0 That will bring you back to a completely empty database. I assembled a complete reference to the package manager

Enable EF Core Migration in Full .NET Project (*.csproj)

筅森魡賤 提交于 2019-12-24 01:15:02
问题 I have a full .NET Framework project (*.csproj) with EF Core data access. How can I have migrations enabled for EF Core in Non-.NET-Core projects (ASP.NET MVC5)? I get the following error: dotnet : No executable found matching command "dotnet-ef" 回答1: The 1.0.0-preview2 and 1.0.0-preview1 releases of EF Core Tools don't work on csproj projects, only project.json. Use the Package Manager Console commands instead. See https://docs.efproject.net/en/latest/miscellaneous/cli/powershell.html 来源:

EF 6 Code-Based Migration: Add not null property to existing entity

╄→гoц情女王★ 提交于 2019-12-24 00:19:28
问题 I want to add a not-null, foreing key column to an existing table. Environment: EF 6,Code-First, Code-Based Migration //Code from Migration class for new entity Currency CreateTable("dbo.Currency", c => new { CurrencyID = c.Int(nullable: false, identity: true), Code = c.String(nullable: false, maxLength: 3, fixedLength: true, unicode: false), Denomination = c.String(nullable: false, maxLength: 50, unicode: false), }) .PrimaryKey(t => t.CurrencyID); AddColumn("dbo.Collection", "CurrencyID", c

EF Data Migrations does not work after close project

天涯浪子 提交于 2019-12-23 12:40:25
问题 i'm using entity framework data migrations. if i change something about entites or something else, i try to use " add-migration MyFirstMigration " on Package Manager Console. But it returns an exception : The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was inclu ded, verify that the path is correct and try again. At line:1 char:14 + add-migration <<<< + CategoryInfo : ObjectNotFound: