All Questions
Tagged with ef-core or entity-framework-core
23,541 questions
0
votes
2
answers
68
views
Can't get two DbContexts to work in same ASP.NET Core solution with EF Core / SQL Server
Two DbContext for two separate databases in same infrastructure project (all in the same namespace if that matters). All entities are in same domain project (entities for each database are in their ...
Tooling
0
votes
4
replies
90
views
Pomelo version compatible with EF Core 10
My employer is making us use ef core 10 and I have problem migrating data because the pomelo nuget package that seem to be out and available is v 9
when will the version that's compatible with ef core ...
1
vote
1
answer
85
views
Using LIKE operator in Entity Framework Core on BinaryData properties
I'm storing JSON data in SQL Server 2022 in a varbinary(max) column. I'm aware that SQL Server 2025 offers a proper JSON data type, but I'm working with SQL Server 2022 for now.
I'm using EF Core to ...
Best practices
1
vote
5
replies
97
views
How to assert the number of SQL queries EF Core executes in integration tests?
I want to write integration tests that verify my ASP.NET Core endpoints don't produce N+1 queries. Specifically, I want a test to fail if an endpoint that should execute 1 query suddenly starts ...
Best practices
0
votes
2
replies
63
views
How to use MiniProfiler EF Core not in ASP.NET Core context?
The official docs say to install MiniProfiler.EntityFrameworkCore and then
public void ConfigureServices(IServiceCollection services)
{
services.AddMiniProfiler()
.AddEntityFramework()...
1
vote
1
answer
106
views
Load additional columns to in-memory collection
I have a list of objects with some, but not all, properties filled in from the database:
class Example
{
public int Id { get; set; }
public int A { get; set; }
public int B { get; set; }
...
0
votes
1
answer
66
views
Add Parent and Child entity in the same context.SaveChanges [closed]
I have a lookup item and a parent entity that I want to add in the same transaction.
So for instance, I use this code:
foreach (ParentDto parentdto in ParentList)
{
Parent newParent = new Parent();...
0
votes
1
answer
101
views
EF Core Table Per Hierarchy: Query with base type in child element "Translation of member 'Parent' on entity type 'Base' failed"
I am trying to write a query like the following with a similar model. I think I understand the problem, but have not been able to edit the model in a way that doesn't add new foreign key columns to ...
2
votes
1
answer
53
views
How do I share a foreign key in an EF Core TPH hierarchy?
I have an Events base class with an abstract child class which itself has two (for now) child classes:
public class Event {
}
public abstract class FooEvent : Event {
public Foo? Foo { get; set; }...
1
vote
1
answer
64
views
Npgsql EF Core does not map enum to PostgreSQL enum type (sent as integer instead)
I'm trying to map some enums in my model to PostgreSQL custom enum types using EF Core, but no matter what I do, EF Core keeps sending the values as integers instead of using the PostgreSQL enum type.
...
0
votes
1
answer
79
views
How to prevent Entity Framework Core from using Table-Per-Hierarchy (TPH) mapping
I use MongoDB.EntityFrameworkCore.
I have 3 classes: Pod, Planet, Asteroid with inheritance from SpaceObject
I want use the default Table-Per-Hierarchy (TPH) mapping for Planet and Asteroid to save ...
1
vote
1
answer
127
views
ASP.NET Core HealthCheck wants a database migration, but I can't figure out what migration it wants
My ASP.NET Core app is throwing this exception, and I can't figure out how to resolve it:
An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The ...
-1
votes
1
answer
139
views
How to filter rows in an Include and ThenInclude statements in LINQ and C#
I'm trying to populate an object with two collections of type ChatSession.
ChatSession contains two types of sessions, Open and Solved.
Edit: Query changed to fit solution from Charlieface.
Add<...
2
votes
1
answer
101
views
PendingModelChangesWarning When Starting API in Docker Container
I have an ASP.NET Core 9 Web API and database in SQL Server. I'm trying to run them in containers, and have the API connect to the database. I have been developing this locally for a while and ...
0
votes
1
answer
51
views
NSubstitute: ToDictionaryAsync: Only sources that implement IDbAsyncEnumerable can be used for Entity Framework asynchronous operations
I'm using .NET 8 with NSubstitute for unit tests.
Even though I setup my repository using IQueryable and BuildMock correctly:
when calling ToListAsync, unit test is working fine
when calling ...