ef-migrations

Entity Framework (.NET) Round-Trip Modelling with Model First?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 09:53:08
问题 I am currently working on a project where I want to use the Entity Framework for the first time. I read much information in the books of Lerman/Miller, in MSDN, the ADO.NET blog and here on stackoverflow about the most recent developments regarding the DbContext API and the Code First Migrations capabilities available since EF 4.3. Since especially the latter are really great, I wondered whether in the meantime it is possible to do the same working "Model First" centered? Is it possible to do

How to add migration in .NET Core Library project in web API core 1.1

≯℡__Kan透↙ 提交于 2019-12-11 08:48:54
问题 I am new in .net core. I am adding migration in .net core Liabrary project in web API core 1.1. using below code. Add-Migration example1 But it's showing below error: 回答1: If you are using VS Code or other editor: In dotnet command cli type: dotnet ef migrations add InitialCreate obs:InitialCreate is the name of migration, you can give any name. If you are using Visual Studio: Create your database Once you have a model, you can use migrations to create a database. Open the PMC: Tools –> NuGet

Entity Framework “A relationship multiplicity constraint violation occurred”

烈酒焚心 提交于 2019-12-11 07:09:31
问题 I received this error from Entity Framework this morning: A relationship multiplicity constraint violation occurred: An EntityReference can have no more than one related object, but the query returned more than one related object. This is a non-recoverable error. The error refers to a very simple One-To-Many relationship between User and Address public class User { public Guid Id { get; set; } public virtual IList<Address> Addresses { get; set; } } public class Address { public Guid Id { get;

Execute Code first Migration

℡╲_俬逩灬. 提交于 2019-12-11 06:19:44
问题 I have installed Windows 8.1 pro and moved all MVC projects to new work-space using VS 2013 Community Edition. All projects were using code first migration. Database Publishing was also done using code first migration. All was running fine before I updated my machine. But Now when I publish web application to remote servers, 'Publish Web' dialog box not showing "Execute Code first Migration", Instead its showing "Update database" for updating database. And when I close it, It modifies the

How do I use MigratorScriptingDecorator in Entity Framework code first?

不羁的心 提交于 2019-12-11 04:51:19
问题 I have problems using the MigratorScriptingDecorator.ScriptUpdate in Entity Framework 4.3.1. When specifying sourceMigration and targetMigration only my initial migration gets written, the rest of my migrations become empty. I have entered a bug report on Microsoft Connect containing reproducing code. https://connect.microsoft.com/VisualStudio/feedback/details/731111/migratorscriptingdecorator-in-entity-framework-migrations-does-not-respect-sourcemigration-and-targetmigration I expect

EF: Seed of Migrations.Configuration vs Seed of DropCreateDatabaseAlways?

泄露秘密 提交于 2019-12-11 04:47:18
问题 My Question was originally: DropCreateDatabaseIfModelChanges fails to update database? But I changed it because the role of these two methods is more ambiguous for me . ................... What I know so far that using DropCreateDatabaseIfModelChanges will recreate the database whenever the schema changes (IfModelChanges). That mean that I don't have to worry about migration, since it will recreate the database from scratch anyway, right? I first created a class DataInitializer inheriting

What's the purpose of StartupProjectName parameter in Add-Migration in EF

半世苍凉 提交于 2019-12-11 04:11:58
问题 As I understand what Add-Migration is doing, it's just compares the current model of code with the model of last applied migration (which has the entire model in its resx file) For the description of StartupProjectName paramter it says: -StartUpProjectName Specifies the configuration file to use for named connection strings . If omitted, the specified project’s configuration file is used. If each migration has a snapshot of whole model, then there would no need to have a database, since the

What is the data annotation for changing nullable and not null data types?

匆匆过客 提交于 2019-12-11 03:42:43
问题 I reckon this should be simple for experienced programmers but here it goes. I am working on a project using entity framework code first.I have also enabled migrations and set to auto (Lovely feature). I stupidly declared one of the datatype wrong in my entity class and now i realised that it wouldn't work with what i was trying to do. Must have been the auto complete feature. But anyways, the field was nullable and now that i have changed it to what i want, it has set the field to "not null"

Does EF Migrations Support Adding Not Null Foreign Keys

人盡茶涼 提交于 2019-12-11 03:41:07
问题 What I'd like is to go from: public class SomeEntity { public int Id {get; set;} //... } To: public class SomeEntity { public int Id {get; set;} public int OtherEntityId {get; set;} [ForeignKey("OtherEntityId")] public OtherEntity Other {get; set;} //... } At the database level, I'm assuming the only way to do this is: Add a nullable foreign key Set valid values on the foreign key Add a not-null constraint Is there some way to make this happen with EntityFramework migrations? What I'm looking

Code First Migrations for dynamically assembled model

巧了我就是萌 提交于 2019-12-11 03:19:42
问题 My database model (sometimes referred to as " context ") is dynamically assembled at startup based on which services and/or plugins are installed. Plugins and services export their model definition fragments through my IoC container and the application core picks them up and runs them when the DbContext.OnModelCreating method is called. The question is: Can I (and how do I) use Code First Migrations with this setup ? (below is more information on what I've tried and what particular problems