ef-migrations

How to associate one table to many parents using EF Code First

坚强是说给别人听的谎言 提交于 2019-12-10 09:42:09
问题 I am building a domain model that requires several tables to be able to be references by more than one possible parent table. Something like you might have a table to store notes or files and those notes and/or files can be associated with different parent entities. Not that the same "file" or "note" can be associate with multiple owners, but that of 10 rows in a "files" table, 3 of them might be owned by rows from a "Customer" table, 3 of them might be owned by rows from an "Orders" table,

Npgsql can't find NpgsqlException when doing Migrations

a 夏天 提交于 2019-12-10 09:28:28
问题 When I do an update-database and an error happens at the database I get: System.Runtime.Serialization.SerializationException: Type is not resolved for member 'Npgsql.NpgsqlException,Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7'. Its trying to tell me about an error but I presume it can't find the exception type its trying to wrap it in so I'm left guessing at my mistake. I'm using version 2.2.5.0 Npgsql.EntityFramework which is currently the latest version. 回答1:

The specified deps.json '$$$' does not exist

吃可爱长大的小学妹 提交于 2019-12-10 04:10:37
问题 I am rather new to the .NET Core, and I got a .NET Core WebAPI project MyWebApp, also, i have .Net Core Class Library project MyLib using EntityFrameworkCore When i try to use Add-Migration, i get the error The specified deps.json [...\MyWebApp\bin\Debug\netcoreapp1.1\MyWebApp.deps.json] does not exist Inspecting the folder, I noticed I have this a file in [...\MyWebApp\bin\Debug\netcoreapp1.1\win10-x64\MyWebApp.deps.json] but i really can't figure what i am supposed to do to resolve this.

Changing primary key data type in Production DB

▼魔方 西西 提交于 2019-12-09 23:43:24
问题 I am using EF code-first. I need to change the datatype of primary key of one table in our production database. public class Course { [Key] public Guid Id {get; set;} //This needs to be changed to int public string Name {get;set;} public virtual ICollection<Group> Groups {get;set;} } public class Group { [Key] public Guid Id {get; set;} public string Name {get;set;} public virtual ICollection<Course> Courses{get;set;} } As the above is a Many-Many relationship, EF has created a join table

Entity framework manually deleted tables cant be generated from EF migration

谁说胖子不能爱 提交于 2019-12-09 16:06:17
问题 I have created migration and created the database and the tables . For example the tables are A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E . Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run

EF 7 Migration to Existing Database

旧街凉风 提交于 2019-12-09 12:22:55
问题 I am working on a web project using ASP.Net 5 and EF7. I have imported all the tables from existing database onto my models in my project. However, I am having problems in regards with migrations. I have created the initial migration, made some changes on particular entity, create another migration following the changes I have made and now want to apply the changes on the database. After running this command below: dnx ef database update [Migration] the dnx is trying to apply the 'initial'

EF Code first migrations not running after deploy to Azure

北战南征 提交于 2019-12-09 11:57:26
问题 I have two folders for my migrations (AuthContext and UserProfileContext), each has their own migration and some custom sql to run afterwards for data migrations and whatnot. This works fine when using package manager console. I Restore from production Run Update-Database -ConfigurationTypeName Migrations.Auth.Configuration Run Update-Database -ConfigurationTypeName Migrations.UserProfile.Configuration Then everything is very happy in the new database, migrations executed data shuffled where

Entity Framework Core: Is it safe to delete Migration.Designer.cs if we will never Revert a migration?

此生再无相见时 提交于 2019-12-09 11:05:44
问题 We have a database schema with ~200 tables. Model snapshot (Migration.Designer.cs) which is created for each migration is ~20K lines. So, having quite a number of migrations really slows down our build on CI (with ~30 migrations building a solution takes 6 minutes with migrations or 4 minutes without them). So, to the question: is it safe to delete model snapshots for old migrations (that we know we will never Revert)? Are model snapshots used for anything else except Revert-Migration? 回答1:

How to add a new code-first migration with a newly-generated database?

痴心易碎 提交于 2019-12-09 07:11:40
问题 I've enabled code-first migrations on my entity framework project, and have added several migrations which do things like rename tables. However, I have now deleted the database and caused entity framework to generate a brand new database based on my latest data model. If I try to run: PM> Add-Migration TestMigration ... it tells me that I need to apply the existing migrations first. So I run: PM> Update-Database ... but the trouble is that it's trying to update a database that doesn't need

Making AddOrUpdate change only some properties

非 Y 不嫁゛ 提交于 2019-12-09 02:59:35
问题 This might be a simple question, however I'm new to Code First and Migrations so bear with me. I'll keep sample code to a minimum to show the problem: I have a BaseAuditableEntity which includes this (among other things, but let's simplify): public abstract class BaseAuditableEntity : BaseEntity, IAuditableEntity { public DateTime CreatedOn { get; set; } public DateTime LastModified { get; set; } } Now a (for example) User POCO inherits from it: public class User : BaseAuditableEntity {