Questions tagged [entity-framework-migrations]
Migrations is a feature of Entity Framework that provides for detecting changes to a code(or database)-first model, and upgrading the database (or the model) schema based on those changes.
3,089
questions
0
votes
1
answer
19
views
When I try to "Enable-Migration" in dataLayer in mvc5 project I get this error. How can I fix it.?
Migration can be enabled in the main project but I receive error in data layer part.
Here it is :
PM> enable-migrations
Exception calling "LoadFrom" with "1" argument(s): "...
1
vote
1
answer
46
views
Any way to detect when DbContext.OnConfiguring() is being called from Package Manager Console?
Is there any way to know if DbContext.OnConfiguring() is being called from the Package Manager?
Here's my method.
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (...
0
votes
0
answers
24
views
Prevent Entity Framework migration from updating foreign keys
I've noticed with EF Core that whenever I make add a new foreign key or anything like that it drops and recreates foreign keys willy nilly. And it's unclear what criteria it's looking at when it's ...
2
votes
0
answers
37
views
Is there an actual risk of memory leak when applying migratons in EF?
According to MSDN, one may utilize the fact that migrations implmenet IDisposable like this.
using IServiceScope scope = app.Services.CreateScope();
scope.ServiceProvider.GetRequiredService<Context&...
1
vote
0
answers
42
views
EF Core 6 EntityTypeBuilder.HasData() doesn't create seed data in migration [duplicate]
I'm fiddling around with a small EF Core 6 practice project, and I'm having some minor problems getting my seed data working properly.
This is some of my code:
CourseEntity
public class CourseEntity : ...
0
votes
1
answer
27
views
Why does running Update-Database on my empty production database not create any tables?
I'm using Entity Framework code-first migrations.
During development, I created the database on the development database server, enabled code-first migrations, added an initial migration, ran Update-...
1
vote
1
answer
42
views
Many to one relationship not shown on find and toList in Linq to entities code first
hello im trying to build a rest api with many to one relationship using code first. here is my two entities :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ...
0
votes
0
answers
13
views
Code-First Migration not returning List for dropdownlist from Existing SQL table
Still studying the use of Code-First so please bear with me here.
I am trying to return a List into a Dropdownlist (the source of this data comes from an existing SQL table that contains products)
...
2
votes
2
answers
92
views
.Net 6 EF Core DbContext and Models In Separate Class Libary
I have a solution with the following projects:
ASP.NET Core MVC website
ASP.NET Core Web API
DAL [incl DbContext and model classes]
Both the website and API reference the DAL and can use it's ...
0
votes
0
answers
35
views
Ltree extension for EF Core and Postgres
I have to add ltree type into my project. I have this:
builder.HasPostgresExtension("ltree")
in my onModelCreating. It's generating this code in the migration:
migrationBuilder....
0
votes
0
answers
18
views
Entity Framework Core with split migrations
I am in the process of migrating from EF6 and .Net Framework to EF Core and .Net.
Previously I had a solution for the data model (Data project below) that built and deployed to a nuget package
...
0
votes
1
answer
21
views
Migration issues after replacing IdentityDbContext with regular DbContext
Originally I was using IdentityDbContext for awhile. Everything was working and I was doing migrations and such. But recently I decided to let AWS Cognito handle the users and password thus no longer ...
0
votes
0
answers
27
views
Entity Framework Core code-first approach migration
No migrations configuration type was found in the assembly 'api_backend'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
...
0
votes
0
answers
30
views
Entity Framework migration debug x86 build
Fail build image
I'm trying to get build for x86 platform but I can't.
When I try to get it for any cpu, I can get it. I need to get build on x86
0
votes
1
answer
25
views
System.AccessViolationException in Entity Framework Core Add-Migration
I get a "System.AccessViolationException" when trying to create a migration with Entity Framework Core.
I already tested inside Visual Studio Package Manager Console and from PowerShell ...
0
votes
2
answers
57
views
EF migrations not working in Github action, same command works locally
I can run the following command locally to update my DB using Entity Framework Core migrations:
dotnet ef database update 0 --project src\MyProject\MyProject.csproj --startup-project src\...
1
vote
0
answers
24
views
How to customize join table name AND primary key names in EF Core 6? [duplicate]
I wanted to customize the join table and primary key fields in EF Core 6 Migrations using Fluent API when it generates this based on the relationships defined below.
public class Product
{
...
0
votes
1
answer
45
views
How do I bind a Boolean array to a C# model using Entity Framework Code First?
I am trying to serialize a JSON response into a Entity Framework Code First model.
The payload is as follows:
[{
"_cs_regimen":"3_per_week",
"_cs_account_email":"...
1
vote
0
answers
130
views
.NET Core 3.1 - dotnet ef add migration error
When I try to create a migration in my ASP.NET Core 3.1 MVC project, I get this error - I need help
Build started...
Build succeeded.
You must install or update .NET to run this application.
App: /...
1
vote
1
answer
60
views
Entity Framework Core - combination between two many-to-many relationships
I have 3 classes a User can have multiple GroupedResources, and GroupedResources can have multiple Resource
public class User
{
public string Id { get; set; }
public virtual ICollection<...
0
votes
1
answer
16
views
More than one migrations configuration type was found in the assembly 'ForApi'. Specify the name of the one to use
I did a migration first time and it works but when I open my project after sometime it shows something like this. I did the same migrations for days.
System.Data.Entity.Migrations.Infrastructure....
0
votes
1
answer
41
views
How to perform migrations to two databases, one for testing and one for production from a single project in EF?
I have a project in blazor wasm, in the appsettings.json file I have two connection strings, one points to the development database and the other to the production database, the production database is ...
0
votes
0
answers
78
views
Unable to add migration: System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions'
When attempting to add a migration for my .net core 6.0 project, I get the following error:
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider ...
0
votes
2
answers
72
views
Add new column in database by migration c#
I have a table which contains two columns (A and B).column A has default value of 1 or 0. I want to add new column C, its default value is 0 and C'values depends on A'value.
How can I do that using ...
2
votes
1
answer
55
views
Entity Framework Core using existing models and database , upgrading from .Net 4.8
I have upgraded a .NET Framework 4.8 site to .NET 6.0 using the migration assistant and a bunch of manual changes to fix stuff. I found that using Add-Migration doesn't work anymore. The migration ...
0
votes
0
answers
21
views
I cant switch Environment to make migration
I try to make migration with Entity Framework in host database. But I wont to change environent from localhost. I tryed dotnet run --environment Production, but it returns environment Development. I ...
0
votes
0
answers
8
views
Entity Framework 6.2 index with include columns and desc sort column within the index
I'm trying to create an index in Entity Framework 6.2 using code first or fluent API.
This is the SQL version of the index that I want to create
CREATE NONCLUSTERED INDEX [IX_My_Index] ON [dbo].[...
0
votes
1
answer
23
views
Have been trying to add migration to my project in ASP.NET MVC using C# but am getting these errors
Could not execute because the specified command or file was not found.
Possible reasons for this include:
You misspelled a built-in dotnet command.
You intended to execute a .NET program, but dotnet-...
0
votes
1
answer
26
views
Entity Framework assign multiple foreign key - code first approach
I don't know how to add two foreign key in the following scenario:
I have two tables, one exists in the database yet (table Market), and I have to create a new table (MarketBranch).
Table Market:
...
0
votes
0
answers
42
views
ASP.NET MVC - How to fix EF migration history differences on local and production server
I have an ASP.NET MVC application that uses EF migrations. Usually when I make changes to the model in local development, I create new migration, and then to apply the changes in production I generate ...
0
votes
1
answer
37
views
How to create a connection between two objects, reference to one and to many in EF Core
I have two classes
class Role
{
string Id { get; set; }
string Name { get; set; }
}
class Permission
{
string Id { get; set; }
string Name { get; set; }
}
I want to create a table ...
0
votes
1
answer
52
views
Duplicate column issue in migration scripts in .net microservice module. I have to resolve duplicate column in my migration which already executed
In .net core microservices, another team works on open source modules, and I extend their modules in my project. I already added one column in a Entity and then same column is added by open source ...
0
votes
0
answers
22
views
Add fields to self-referencing many-to-many relationship in Entity Framework Core
I have an existing data model in EF Core 6, which has a self-referencing many-to-many relationship. It's set up as follows:
public class Item
{
[Key]
public long Id { get; set; }
public ...
1
vote
0
answers
27
views
How to get active provider in EF6 DbMigration?
I am struggling with generating conditional code enabling a single migration to target multiple providers - in our project we use EF6 with MSSQL and PostgreSQL.
Is there a way to determine the active ...
0
votes
0
answers
19
views
Production Website Error After Model Change - The model backing the '-Context' context has changed since the database was created
I have this project in Visual Studio that I recently published and hosted on IIS on a different machine. Initially I just backed up the localdb on my dev machine and restored it to the SQL Server on ...
0
votes
0
answers
17
views
How to TEMPORARILY exclude one table from automatic code first migrations in the Entity Framework?
This already covers the exclusion via ExcludeFromMigrations - however, our use-case is that we have new entities that are in a lot of flux that we don't (yet) want to tie down via migrations, so we'd ...
0
votes
0
answers
48
views
How to add new values for custom types using Entity Framework Migrations?
I have let's say an entity named User with an Enum type property named user_type with the following values: admin and editor.
I want to add a new value to this Enum: contributor, but I'm not able to ...
0
votes
0
answers
60
views
Why EF Core doesn't add an underscore when generating Foreign Keys?
I'm migrating from EF 6 to EF Core (code-first approach) but when I run the system I get an error
Invalid column name TableNameTableId
The problem is that the column is called TableName_TableId.
For ...
0
votes
0
answers
200
views
Dotnet ef Migrations error - Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies'
I'm getting the following error when I run the following command.
dotnet ef migrations add init
Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity ...
0
votes
0
answers
26
views
There is already an object named 'BookInvestments' in the database
I know a lot of answer for this question is available here but I have tried all out and not working. Maybe because my issue is different..
So i have an application already already in use with code-...
0
votes
2
answers
13
views
How can we remove first migration in Entity Framework Core Code first approach
As we know when we want to remove latest migration, We update the database to latest but one migration so we can remove the latest migration but if want to remove first migration don't have latest but ...
0
votes
1
answer
19
views
.Net Core EF DBContext Migration not working
So, there you are venturing into code-first EF design with Clean Architecture. You have your models in .Core project, db context defined in the .Infra or .Data project. You getting ready to create the ...
0
votes
1
answer
229
views
EF Core: Unable to materialize entity instance of type 'Resource'. No discriminators matched the discriminator value ''."
This Stack Overflow question does not solve the problem and is not related: .NET Core: "Unable to materialize entity instance of type 'IdentityUser'. No discriminators matched the discriminator ...
0
votes
0
answers
39
views
Calling procedure using linq c#
I use this code here to get data from procedure
string msg = "";
OracleConnection con = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=PORT))...
0
votes
1
answer
168
views
Updating databases in Entity Framework for development and production environments in ASP.NET Core
How do I apply EF migrations to multiple databases, referencing either a Development or Production environment as required?
TL;DR
I'm developing an ASP.NET Core MVC application using Entity Framework ...
0
votes
0
answers
42
views
What is an alternative to running SQL query in code-first migration script?
Goal is to add data to DB table.
I can generate an empty migrations script and add this in Up() method.
migrationBuilder.Sql($"INSERT INTO [User].[ExtraUser](Id,Name,Description)" +
...
0
votes
1
answer
32
views
How can I add two property in my model in EF code first from one model?
I want to add two properties from the city model:
after migration this error shows up:
Unable to determine the relationship represented by navigation
'City.Orders' of type 'ICollection'. Either ...
0
votes
0
answers
23
views
Enable-Migrations command give and error Exception has been thrown by the target of an invocation
I have one web project and second DAL project which built in .NET Framework 4.7.2
When I am try to run any migration commands using "Package Manager Console"(DAL Project) it give me an error:...
0
votes
1
answer
66
views
When migrating from EF to EF Core do you need to create a new migration with the entire database structure?
I'm migrating an API from .NET Framework 4.7 to .NET 6 (including EF to EF Core) and when I create the dbContext and execute the Add-Migration command, it creates the whole structure of the database, ...
0
votes
1
answer
126
views
Create database and generate table with dotnet migration from created models
I'm newer to EF core and I followed an Asp.net core tutorial on Youtube (Presented in French ) Link of the tutorial, this tutorial helped me to create my first Asp.net core application (.NET 5) using ...