Questions tagged [ef-migrations]

1

votes
0

answer
6

Views

change entity framework core code first migration name format

ef core using system calendar format for generating migration names. example of standard migration name for the Gregorian calendar on windows: 20190206144020_MIGRATION-NAME But if the date format of Windows is something other than the Gregorian, like Persian calendar the ef core migration name gene...
AliReza
1

votes
1

answer
805

Views

Unknown CS1003 Error

I can't compile my project for code-first migrations in entity framework past a certain point. I am reading in values from xml to populate a table. I have the following code: //EnrolmentProgramStartDate var programQuery = from r in context.EnrolmentPrograms select r; var programList = programQuery.T...
Ben
1

votes
0

answer
190

Views

Can not add migration in Entity Framework

Added a new field to RegisterViewModel: [Required] [Display(Name = 'Name ')] public string Name { get; set; } Added in AccountController: if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Name = model.Name }; var result = await UserManager.Create...
Maksims
1

votes
0

answer
107

Views

Best way to use ef migration on asp mvc website deployment on server and local development

I'm developing websites and i want to update database fields as project grows. to use ef Migrations for adding new fields and changes to db , i add migration base on db on local by connection string like this: this moment I have migrations folder with configuration and migration file that has some t...
Mahdi Rezaei
1

votes
0

answer
158

Views

Using custom MigrationOperation in CSharpMigrationCodeGenerator

I would like to create my own migration operations for the CSharpMigrationCodeGenerator, so I created my own migration operation derived from MigrationOperation. public class CustomMigrationOperation : MigrationOperation { public CustomMigrationOperation() : base(null) { IsDestructiveChange = false;...
Rod
1

votes
1

answer
90

Views

ASP.Net MVC migration: access field you're deleting

During a code-first migration, is there any way to access a field that is guaranteed to still exist in the database but may not exist in your model anymore? Context: I am trying to switch from a one-to-many-relation (a one-way reference) to a many-to-many-relation (a mapping table). Of course I woul...
Zeust the Unoobian
1

votes
1

answer
83

Views

Update-Database connects to wrong database

I set connection string in my Startup.cs (Startup class and ConfigureServices method). Sample code below: if (_currentEnvironment.IsProduction()) { connectionString = 'ProdConnection string here ..'; } else { connectionString = 'Devl connection string here ...'; } In the Package Manager Consoler of...
user3885927
1

votes
0

answer
1.1k

Views

EF Core multiple DbContexts for one database

I'm going to separate DbContext as a individual project and share the DbContext with two projects. Now assume I have: Project.Data namespace Project.Data { public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } protected ove...
seed.of.apricot
1

votes
0

answer
366

Views

EF6 code first and VIEW

I would like to add a VIEW to the database, and query the data from this VIEW using L2E. I use migrations for maintaining database schema. I added one class that should MAP to a VIEW columns. As an example, this class has only two properties [Table('View_Data')] public class ViewData { [Key] public...
Goran
1

votes
2

answer
731

Views

ASP.NET Core 2.0 Code First Migration - New Database

I currently have an ASP.NET Core 2.0 project and I've just implemented code first migrations to the localdb and have around 3 migrations including the initial create. I'm wondering what the correct process is to change to a new database? Is it simply a case of updating the connection string and runn...
Mihto
1

votes
0

answer
84

Views

Adding a new relation to existing database using entity framework

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 fol...
1

votes
0

answer
98

Views

Entity Framework Migration Error in Changing Column Type

I just changed my entity from int to byte in one of my class and added the migration. When i run the update-database command in package manager console i got the following error: Error Number:5074,State:1,Class:16 The index 'IX_GenreId' is dependent on column 'GenreId'. The object 'FK_dbo.Movies_db...
Talha Faraz
1

votes
1

answer
985

Views

No migrations were applied. The database is already up to date

I created a migration and updated the database without any problem. However, when I change my environment with $env:ASPNETCORE_ENVIRONMENT='Production' and rerun dotnet ef database update it is using the new environment but showing that 'The database is already up to date.'
nPcomp
1

votes
2

answer
167

Views

Entity Framework adds extra field in database. and adds both members of composite key

I'm struggling with composite keys and extra fields being generated by Entity Framework. I have a question about something which I think is odd. Let's say I have a one to many relationships with these classes: File (dossier) [Table('Dossier')] public class Dossier { [Key] public string Dossiernummer...
S B
1

votes
1

answer
669

Views

AspNetCore 2.0.5 Add-Migration trying to create table instead of alter existing

AspNetCore.All 2.0.5 decided to Create a new table for a migration with the same name as one that already exists, instead of altering the existing table. Add-Migration produces a migration successfully, but when running Update-Database it throws an error because a table with the same name already e...
jv_
1

votes
0

answer
15

Views

Access to the properties of the Context object during Code First Migration

I have an EF migration that creates a linked server if it doesn't exist. This is working well, but following this are a number of migrations that merge data in from that linked server. Before I run these I need to issue a USE [MAIN DATABASE NAME] because I switched to MASTER to create the Linked S...
Mike Devenney
1

votes
0

answer
24

Views

Are dotnet 1.1.4 migration files no longer compatible with dotnet2 migrations?

It seems like when I try to do a dotnet ef migrations add , I get a huge migration file that seems to include everything from the beginning of my migrations since 1.1.4. Are the snapshots from 1.1.4 not compatible with 2.0.0? Since its adding stuff from the very begininng, when I run dotnet ef datab...
user6728767
1

votes
1

answer
39

Views

Detect Configure method invoked from migration

I have an ASP.NET Core 2.0 application and I am seeding the database from the Configure method. The problem is that the method is also called during migration, causing an error since the database is not created yet. There is a way where I can check if the method is called from migration? public void...
Dino
1

votes
0

answer
66

Views

Exception when creating migrations for Entity FrameworkCore 2.0 in Xamarin Forms App (.NET Standard 2.0)

I have been trying to create an initial migration within my .NET Standard 2.0 cross-plattform Xamarin project. I have installed the console tools following the instructions here: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell I've enabled cross-framework targeting for my share...
LetzFlow
1

votes
0

answer
822

Views

“An Error Occurred while updating the entries. See the inner exception for details.” - unable to view “inner exception”

I am working in ASP.NET MVC5 attempting to make a fairly simple program for a school assignment. I got this error... because of this line of code: context.Facilities.AddOrUpdate(x => x.ID, new Facility() { ID = 1, FacilityAddressId = 1, Name = 'School Playground', OwnerId = 1, Indoor = false, Sport...
SlyFiye
1

votes
0

answer
142

Views

How to generate column update option in model create net core 2.1?

I use NetCore 2.1 SDK, database is Mysql (5.7.21) with Pomelo package connector (2.1 RC2). I have 'updateAt' column in my database table, type datetime. I have scaffolded database where column was: `UpdatedAt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP after creating migration, t...
apincik
1

votes
0

answer
120

Views

Entity Framework migration issue

I am using Entity framework and code first approach in my project. I have done some Migrations to my server database and it was working fine. now I added a few more tables and try to create a migration by add-migration command to the database on server. The command runs with no error and created a...
Jinto Jacob
1

votes
1

answer
527

Views

EF Core GUID Database Generated in Abstract base class

So my entities inherit from a class like this: public abstract class EntityBase { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid UuId { get; set; } [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } [Timestamp] public byte[] RowVersion { get; s...
Jammer
1

votes
0

answer
122

Views

Updating a table using the EF Seed method

I'm trying to normalise a table by introducing a new table, and then a reference to an entry in that table. For example, I have a table similar to this: Id | MyData | Description | Date 1 | Test | Testing | 2018-07-09 2 | Test Data | Testing 2 | 2018-07-09 3 | Test...
1

votes
0

answer
111

Views

Migration error when adding profile data to ASP.NetCore Identity

I am using Asp .netcore 2.0 on Visual Studio 15.7.4 and Its in app Identity system. According to this post in order to add new profile data all I need to do is to add it inside ApplicationUsers.cs and the add migration and update database. Migration works fine before adding the new property but fail...
farshad
1

votes
0

answer
373

Views

How to work with Migrations on rider?

I tried to add-migration and other migration operations on Rider with Entity Framework 6 project. I tried two approaches. Using inline tool from menu Tried this - https://blog.jetbrains.com/dotnet/2018/04/06/entity-framework-support-rider-2018-1/ I am using SQL Server LocalDB and no tool appears in...
Dmitrij Polyanin
1

votes
1

answer
930

Views

Add migration - Both Entity Framework Core and Entity Framework 6 are installed

I have a solution with multiple projects one of them with EF 6 and another one with entityframeworkcore. The migrations were working fine before adding EF6 project, but now I can't use the migration's command : add-migration 'anything' Both Entity Framework Core and Entity Framework 6 are installed....
Shahrukh Ahmad
1

votes
0

answer
21

Views

EF Migration - Micro Serivces - Fetch Value from DB1 and Update in DB2 using EF Migration (for Patching the data, as one time)

We have Micro Services, M1, M2, M3 etc. Each has its own database and using EF migration we manage the scripts for each database. Now our requirement is to pull some value from M1DB (MicroService Database1) and update into M2DB (Microservice database2). This is a one-time activity to patch some valu...
Badri Prasad
1

votes
0

answer
143

Views

Entity Framework 6 Code First Migration not working with Oracle Database

I am developing an ASP.NET MVC 5 application with EF6 and Oracle database. I am using the code First approach, I created my entities and My Context class and then I tried the Enable and Add a Migration but I got this error. However, If I use SQL SERVER in the place of Oracle database it works fine...
Haytham
1

votes
0

answer
49

Views

Custom EDM Mapping not used runtime

I am trying migrate from EF5 to EF6. After installing EF6 package, I updated required namespaces & *.tt files but then when I tried to update model from database, encountered certain type mapping errors which turned out to be due to change in default number mapping in EF6. I am using oracle provide...
Amol
1

votes
1

answer
647

Views

EF Core 2.1 seeding data primary key

I have just run into an issue, reminiscent of chicken and egg situation. I'm trying to seed data in EF 2.1.3. I have a class called 'Sample'. public class Sample { public long Id { get; set; } public string Name { get; set; } public string Description { get; set; } public bool IsActive { get; set;...
Nick Goloborodko
1

votes
1

answer
54

Views

Compile error "Type 'MyMigration' already defines a member called 'Up' with the same parameter types

I have a very simple code-first dotnet core webapi project generated from netcoreapp2.1 in VSCode and I also added two migrations using dotnet ef migrations add [migration-name]. Everything seems to work as expected, except I suddenly get this compile error (you can disregard the brackets in the mig...
Stig Perez
1

votes
0

answer
37

Views

Unable to execute create stored procedure using Entity Framework 6 with npgsql in postgresql code first

I am not able to create a stored procedure in npgsql using ASP.NET MVC 5. My migration code is: CreateStoredProcedure('dbo.CustomerDetails_Insert', p => new { p_chrv_ah_name = p.String(maxLength: 150), p_chrv_ah_desig = p.String(maxLength: 50), p_chrv_org_name = p.String(maxLength: 150), p_chrv_org_...
saswat saubhagya
1

votes
0

answer
62

Views

How to reset Database Migrations in Net Core

I have many database migrations created while different people working on the same project. Once we have completed the development, how can we reset/clear all the database migrations? or Can we reduce the count of them? I think that Deleting snapshot, all the migration files along with clearing _Mig...
suraj13k
1

votes
1

answer
97

Views

EF-Core Update-Database command fails (cannot load type from Microsoft.EntityFramework.Design 2.1.4.0)

I cannot run my migrations - this is very annoying as I cannot move on with my project... I think it must be something with ef tooling because some time back (one month) the migrations in this project worked. The Add-Migration command works successfully, but subsequent Update-Database fail with foll...
videokojot
1

votes
2

answer
83

Views

One to one relation in EF Core using Fluent API [duplicate]

This question already has an answer here: One-to-Zero relationship with Entity Framework Core 2.0 1 answer I am using EF Core 2.1 How to map one-to-one relationship in EF Core. I have Customer & Course domain entity where one customer will have one Course. This is my how my Customer & CoursePOCO...
Kgn-web
1

votes
0

answer
92

Views

Invoke-SqlCmd for migrations script fails on columns that will be introduced

I'm trying to get database migrations into my release pipeline definition, roughly following this aproach - dotnet ef migrations script --idempotent as part of the build pipeline, and then an Invoke-SqlCmd task pointing to the resulting script as part of the release pipeline. However, I have made on...
Tomas Aschan
1

votes
0

answer
30

Views

Not able to create dynamic tables using Entity Framework with a code-first approach

I am trying to create tables dynamically using Entity Framework with a code-first approach. I am dynamically creating class using the System.Reflection.Emit namespace. I am able to add [Table] attribute to class and was also able to add [Key] attribute to a int property. When I try to create table i...
Veeresh
1

votes
1

answer
42

Views

.NET CORE 2.1.1 with Entity Framework Core 2.1.4 Code First: Conversion failed when converting date and/or time from character string

I have a Extension Method to seed my table after created: public static class ModelBuilderExtensions { public static void Seed(this ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.HasData( new Event() { id = 1, WhenDate = DateTime.Now.AddMonths(1) } ) } } I created migration file...
A. Morel
1

votes
0

answer
43

Views

Update-Database: An error occurred while accessing the IWebHost on class 'Program'

I have a .NET Core web project that requires some User Secrets setup (it is on GitHub). I go and set up my local User Secrets, but then when I run Update-Database in Package Manager Console to create the database, I get the following error: An error occurred while accessing the IWebHost on class 'Pr...
J86

View additional questions