Questions tagged [entity-framework]
For questions about Entity Framework for .NET Framework, max. version 6.5.1, (6/17/2024). Use [entity-framework-core] for current .NET versions., accompanied by a version-specific [ef-core-xx] tag.
entity-framework
91,810 questions
1
vote
2
answers
71
views
Linq query io.DrpString.Contains(dienstregelpunt)' could not be translated
I keep getting error
.DrpString.Contains(dienstregelpunt)' could not be translated.
I have a string[] dienstregelpunten array and a database field containng ...
-1
votes
0
answers
61
views
Entity configuration for multiple nested value objects in temporal table
I'd like to create a table in my SQL Server. My entity in code contains multiple nested value objects.
My Student table is a temporal table. All properties and ...
2
votes
1
answer
131
views
Entity Framework/Linq Get Last Record From List With Condition
I have a list of records, by multiple UserID's.
...
Tooling
0
votes
4
replies
92
views
Is there a Database First approach in Java like Entity Framework in C#?
I’m used to working with a Database First approach in C#. I design my database schema (often with MySQL Workbench) and do a forward engineering, then generate my C# models using Entity Framework’s. ...
4
votes
2
answers
499
views
error MSB4057: The target "ResolvePackageAssets" does not exist in the project
I tried adding a migration via dotnet ef migrations add InitialCreate but got the following error
...
Advice
0
votes
2
replies
52
views
How to set the value in the basic many-to-many relationship example of EF?
Here's a basic example from the official .NET documentation for a many-to-many relationship using EF and .NET:
...
1
vote
4
answers
223
views
How to use .Include() in Entity Framework across classes without repetition [closed]
I am looking for a way to use the .Include clause of Entity Framework while avoiding duplicate code.
I have a lot of classes, and every class has a method which ...
2
votes
1
answer
92
views
How can I instantiate and populate nested/complex objects with Select() in Entity Framework 6?
I am attempting to backport some code written with Entity Framework Core to Entity Framework 6. I've encountered an issue where EF Core can successfully instantiate a complex DTO (i.e. an object with ...
1
vote
1
answer
117
views
How would I use N.EntityFramework.Extensions to insert into another table
I am trying to use the InsertFromQuery() to add data to a SQL table:
...
0
votes
1
answer
161
views
SQL query produced by Entity Framework very slow
I have the following query being generated by EF:
...
1
vote
0
answers
78
views
Mysql ConnectionAttempts increased on AWS RDS after dotnet 6 update to 8
After updating our Dotnet API from dotnet 6 to 8 the connection-attemps on AWS RDS increased significantly (see attached picture).
The API is running in a docker-container.
We use a MYSQL RDS instance ...
1
vote
1
answer
93
views
EF Core populating its navigation although it shouldn't
I am reading the book C#12 In a Nutshell. The author says:
Loading navigation properties
When EF Core populates an entity, it
does not (by default) populate its navigation properties:
...
6
votes
1
answer
223
views
How to manage Entity Framework migrations and databases when using Git version control?
We are planning to use a Gitflow workflow and a shared test database. We currently use EF 6.5.1 and have automatic migrations disabled.
Problem: if a developer runs ...
1
vote
2
answers
146
views
C# Entity Framework use value from joined object and only return main object
I am trying to populate a object with additional data from another object with Entity Framework from our data tables.
...
2
votes
0
answers
412
views
Enum mapping hell PostgreSQL => EF Core 9
I am creating a brand new project to prototype an ASP.NET Core 9 Web API backend with PostgreSQL using the latest Entity Framework Core 9 and Npsgsql 9. Everything was going well until I hit a table ...
0
votes
0
answers
62
views
I can't create my custom filter in HotChocolate 13.5.0, where can I view detailed documentation or code examples?
I'm trying to create my own filter for a specific type of data in hotchocolate.
I created a class from FilterInputType<MyType> and specified an additional ...
0
votes
1
answer
103
views
EF Core, Work locally, save/update entire tree of data
I have a TaskFlowTemplate, pretty standard but a bit complex. Our users will have the ability to work locally in memory without need to save after every changes. My ...
0
votes
0
answers
71
views
Entity type cannot be tracked error - Entity Framework
I have been messing with this for days now and I'm at a loss. I keep getting
The instance of entity type 'LineItemHeader' cannot be tracked because another instance with the key value '{id:1}' is ...
0
votes
1
answer
111
views
How to resolve EF Core continuous migration error with npgsql HiLo?
I'm using Hilo with a custom sequence name. When creating migrations, EF Core always creates a migration to drop the sequence with the normal name. Since EF Core 9.0, this produces a runtime exception ...
1
vote
0
answers
200
views
Orphaned pg_temp_# and pg_toast_temp_# schemas in postgresql 17.5 slow down ORM model update
I am running PG 17.5 Windows using the EDB community distribution. I am using Entity Framework ORM with Devart's dotConnect for PostgreSQL. The issue I am about to describe did not occur under PG 13....
2
votes
2
answers
128
views
How to call var scope = ScopeFactory.CreateScope(); and still have one depency resolved from rootProvider
I have situation like this: I have two Blazor components, both using dbContext and I get popular error
A second operation was started on this context instance ...
3
votes
1
answer
113
views
How to add custom pluralization of table names when using "dotnet ef dbcontext scaffold" command
I am running the following command to scaffold C# models of an existing database:
...
0
votes
1
answer
127
views
Why can't Entity Framework soft-delete via SaveChanges? (and an alternative solution)
I want to implement "soft delete" in my application, meaning that instead of physically removing records from the database, I set an IsDeleted flag to ...
-2
votes
1
answer
107
views
Adding a file path to the local storage in the ViewModel MVVM NET MAUI [closed]
enter image description here
My task is to get a photo from the stream and then save it to local storage and pass the path to this photo to the ViewModel, and then save the path in the database. I put ...
1
vote
1
answer
77
views
dotnet ef doesn't seem to be using password provided by UseNpgsql with Mac Postgres.app
I have a web application:
...
1
vote
1
answer
109
views
How to Track Full Update History of TPT Entities in EF Core with MySQL [duplicate]
I'm designing a .NET Core application using EF Core with a MySQL database, following a Table-per-Type (TPT) inheritance strategy.
I have a base Report class with several derived types such as ...
-2
votes
1
answer
104
views
EF6: optional foreign key always null
I have a C# (C# 7.5) application that is using EF6.
I have a table that contains two foreign keys. Both are one:one relationships and both are required.
When I load a record from the database, the ...
0
votes
1
answer
341
views
NETSDK1064: Microsoft.EntityFrameworkCore.Analyzers 9.0.6 not found after NuGet restore (possibly due to long path issue)
I'm trying to build a .NET 9 project using Visual Studio, and I keep getting the following error:
Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1064: The Microsoft....
0
votes
0
answers
202
views
Why the 'GetPendingMigrations()' method brings already applied migrations?
Im using EF Core in a .NET 9.0 Web API project, and I was trying to implement automatic migrations on API startup. The current project makes use of Docker containers (Configured using a Docker compose ...
0
votes
1
answer
130
views
Check if rows exists, and add if not
This is my table:
user_id
last_activity_time
1
2025-06-20 11:00:01
2
2025-06-20 11:00:02
3
2025-06-20 11:00:03
4
2025-06-20 11:00:04
Let's say, my input parameter if a user id list: ...
1
vote
1
answer
138
views
Why this Linq doesn't equals null?
I'm working on a project that uses the legacy .NET Framework 4.x. I'm using LINQ here, but it's not behaving as I expected, and I'm not sure what mistakes I've made.
I have the following MySQL table:
<...
1
vote
1
answer
90
views
LINQ query not grouping and when returning, missing data
I have grouped orders from the orders table so an order can have one or more purchases of a product with in an order. The problem is that when I purchase a single product that order with one product ...
1
vote
3
answers
120
views
C# Linq include VS Navigation when join
This post is translated Ko to Eng.
I understood that using .Include() in Entity Framework triggers eager loading, and that when ...
1
vote
1
answer
82
views
"inheritance" between mappings using Expression<Func<...>> for Entity Framework queries
A rather complicated object mapping I've inherited uses static Expression<Func<...>> in the .Select call (from my ...
0
votes
1
answer
169
views
How can I fix/avoid exception saving entity in system-versioned table?
I'm encountering an issue when executing transactions on system-versioned tables (SQL Azure) in my ASPNET Core + Entity Framework app.
In my database, there are two system-versioned tables:
dbo....
0
votes
2
answers
96
views
How can I convert an EntityQueryable to an IIncludableQueryable?
How can I convert an EntityQueryable to an IIncludableQueryable? I get this error...
Object of type
'Microsoft....
2
votes
1
answer
52
views
Trying to access a child property for a Search Method EF
I am attempting to create a method that filters data based on what the user types into my search bar. What to want to do is filter based on the name of a suspect. "Suspects" being a child ...
1
vote
1
answer
190
views
Are there any downsides to using AsAsyncEnumerable over an Entity Framework query?
My use case is that I want to retrieve a large number of records from the database and write them to a file stream, e.g. a .csv file.
To reduce memory pressure I ...
0
votes
0
answers
70
views
Entity Framework Add-Migration is recreating entire database
I am working on a Blazor Web App using SQL as my database. My initial database migration works fine.
However, when I make a change to one of the model classes, even a simple change, and try and add a ...
1
vote
0
answers
80
views
How to include related entities in many to one relation when no FK defined in the DB schema
I have the following 2 tables defined in the DB (follows) with fixed schema, meaning I am not allowed to change it. Some details were omitted for readability:
...
0
votes
1
answer
25
views
EF Core Northwind tests failing with "System.MissingMethodException Method not found: 'Void Xunit.Assert.Equal..."
I'm trying to run the EF Core Northwind tests for our EF Core implementation and the calls to AssertSql (which call AssertBaseline()) fail as below. This is with .NET 8, Xunit 2.9.3, in Rider, on ...
0
votes
1
answer
63
views
How to get a drop down list of imported values, and use it to filter a foreach list of values below it
I have a page that lists a bunch of doctors with their specialties, and a drop down list of specialties above it. When you initially open the page, it shows all doctors below the drop down list. I ...
0
votes
1
answer
88
views
Can I add a second field to an "await _context" statement?
I have an await _context statement that returns a single value from a table (StatusDesc). This ...
1
vote
1
answer
138
views
Same projection mappping in IQueryable.Select but with Varied Child Collection filters in EF6
I have methods used in IQueryable.Select(...) that shares the same logic of mapping an Entity class to a DTO class, but filter the navigation properties in the ...
0
votes
1
answer
145
views
Error migrating to Microsoft.Data.SqlClient in EF6: 'SqlParameterCollection only accepts non-null SqlParameter type objects
Currently migrating to using Microsoft.Data.Sqlclient within our app that uses Ef6.
We are on Ef 6.5.1 and using the Microsoft.EntityFramework.SqlServer package.
When attempting to run a query with ...
0
votes
1
answer
61
views
Entity Framework and database
I'm working on an EF project. This is my entity:
...
0
votes
0
answers
196
views
How to set a custom migrations history table name using builder.AddNpgsqlDbContext<AppDbContext>() method in .NET Aspire?
I'm building a .NET Aspire-based application using PostgreSQL with Entity Framework Core. I’m registering my DbContext like this as I am using ...
0
votes
1
answer
79
views
Explicitly Loading filtered navigation property via Load() not working
I have a query that I want to return an entity with a filtered collection navigation property. According to the EF6 document I should be able to load it via explicit loading. However, after the ...
0
votes
0
answers
15
views
Entity Framework code first a many relationship to oneself [duplicate]
I am not seeing an answer to configuring what I need out there on the interwebs and here. Imagine I am working on a pricebook app (for fun). One part of my data model is ...
0
votes
2
answers
151
views
How to make LINQ query faster
Running NbLinksExpirationStatus takes about 12 seconds to execute, which is not fast enough for what i am trying to achieve. Could it be Contains() problem and is there any way i can make it execute ...