91,791 questions
Advice
0
votes
7
replies
118
views
How to filter a query with the values from a list in ef core
I have a list that is the result of a db query. I need to be able to query another table but filter that query based on the first list. In a perfect world I would join these two tables but they are ...
0
votes
1
answer
114
views
Depending DataSeeding in Abp framework
I tried to DataSeed some data, but I got this error: SqlException: The MERGE statement conflicted with the FOREIGN KEY constraint "FK_SubCategories_Categories_CategoryId".
1st I tried to do ...
0
votes
4
answers
281
views
SQL query running slow
I have the following query generated by EF:
SELECT
[t].[Id], [t].[ActiveStateLicenseId], [t].[AvailableDate], [t].[City],
[t].[CreatedBy], [t].[CreatedOn], [t].[DateOfBirth], [t].[Email],
...
0
votes
1
answer
126
views
How to apply a two-levels' SelectMany using expressions in a generic way in C#
Let's have 3 entities with the same base class for ID's:
public class EntityBase
{
public int Id { get; set; }
}
public class Company : EntityBase
{
public string Brand { get; set; }
public ...
1
vote
2
answers
98
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 dienstregelpunten as a csv field. See ...
2
votes
1
answer
137
views
Entity Framework/Linq Get Last Record From List With Condition
I have a list of records, by multiple UserID's.
TableID UserID Status
------------------------
1 3 3
2 4 3
3 3 4
4 4 3
5 5 4
6 ...
Tooling
0
votes
4
replies
119
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
724
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
C:\Users\tmsta\OneDrive\source\repos\Server Default\TrevorsTempMonitorApp\TrevorsTempMonitorApp.csproj ...
Advice
0
votes
2
replies
53
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:
public class Post
{
public int Id { get; set; }
public List<Tag> Tags { get;...
1
vote
4
answers
228
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 looks something like this:
query = (...
2
votes
1
answer
104
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
122
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:
await cx.Users
.Where(x => x.Country == "Romania")
.InsertFromQueryAsync("Mailbox", mb => ...
0
votes
1
answer
168
views
SQL query produced by Entity Framework very slow
I have the following query being generated by EF:
DECLARE @__term_0 VARCHAR(7) = 'woodrow'
DECLARE @__p_1 INT = 0
DECLARE @__p_2 INT = 15
SELECT [t].[Id], [t].[City], [t].[Contact], [t].[CreatedBy], [...
1
vote
0
answers
82
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
96
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:
using var ...
6
votes
1
answer
274
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 Update-Database (or dotnet ef ...
1
vote
2
answers
151
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.
public partial class Maintable
{
public int Id { get; set; }
public int ...
2
votes
0
answers
576
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
75
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 field for filtering in it. For this ...
0
votes
1
answer
107
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 primary key is int Id.
public class ...
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
123
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
280
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
150
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 before a previous operation completed. ...
3
votes
1
answer
135
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:
dotnet ef dbcontext scaffold "<conn string>" Microsoft.EntityFrameworkCore.SqlServer
I would like to ...
0
votes
1
answer
147
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 true. My expectation is to intercept ...
-2
votes
1
answer
120
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
86
views
dotnet ef doesn't seem to be using password provided by UseNpgsql with Mac Postgres.app
I have a web application:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<...
1
vote
1
answer
114
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
117
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
416
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
222
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
131
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: [ 3, 4, 5 ]. I ...
1
vote
1
answer
140
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
93
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
157
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 I include multiple entities, they would all be joined in the SQL query — ...
1
vote
1
answer
92
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 research these seem to be called "Expression Trees", but for ...
0
votes
1
answer
183
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
117
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.EntityFrameworkCore.Query.Internal.EntityQueryable1[Extenso.TestLib.Data.Entities....
2
votes
1
answer
53
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
230
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 thought I'd use it as an ...
0
votes
0
answers
83
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
82
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:
CREATE TABLE [periods]
(
[id] [int] ...
0
votes
1
answer
26
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
64
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
90
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 StatusId is unique for each ID. The current code only retrieves the StatusDesc:
var status = await ...
1
vote
1
answer
143
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 projection differently. The problem is ...
0
votes
1
answer
160
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
62
views
Entity Framework and database
I'm working on an EF project. This is my entity:
namespace AnagraficaEF.DA
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System....
0
votes
0
answers
209
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 Aspire.Npgsql.EntityFrameworkCore.PostgreSQL package:
...