23,540 questions
0
votes
2
answers
60
views
Entity Framework Core: how to get the list of attribute codes for each item?
I am writing a Web API endpoint, data comes from SQL Server, and I'm using EF Core 8.0.
I have a table of products and another table that maps the product codes to product attributes (one-to-many) ...
1
vote
0
answers
70
views
How to async fill the navigation property used for filtering when paging?
Learning EF Core, I am changing my mind on how to get the list of products with additional information (here symbolic code) -- see the loosely related (abandoned approach) at How to conditionally ...
1
vote
1
answer
107
views
'SQLite Error 19: 'FOREIGN KEY constraint failed'.' while try to insert data
I am trying to run my database code, but I keep getting this error and I've done whatever I can think of to fix it, whether it is random posts, or chatgpt, but I can't seem to figure it out. The ...
Best practices
0
votes
4
replies
69
views
Should I create navigation properties for BaseEntity's CreatedBy/ModifiedBy fields in Entity Framework Core?
I'm building an e-commerce application with ASP.NET Core Web API using Entity Framework Core and ASP.NET Core Identity. I have a BaseEntity class that tracks audit information (who created and last ...
-4
votes
2
answers
201
views
Why does this code return a null reference exception without warning?
My understanding of C#'s null safety features (from C# 8.0 onwards) is that (possibly) null variables must be typed as nullable and that the compiler will statically detect any parts of the code which ...
Best practices
0
votes
2
replies
68
views
Filling the `entityIds` property in EF Core
I am currently developing a module for an ASP.NET Core Web API that uses EF Core to talk to MySQL. The problem is I have no idea how to make EF Core fill the entityId property.
Here is the example ...
1
vote
1
answer
93
views
How to conditionally compose the EF from parts?
I have two tables Products and CustomerProduct. I need to compose an Entity Framework Core object that returns the result based on arguments of the Web API endpoint method.
The method roughly works ...
0
votes
1
answer
108
views
EF Core 9 migration fails on production database copy with "Cannot release the application lock" error
I'm using EF Core 9 and I'm trying to run a migration against a copy of our production database.
On our local development databases everything works, but on the production copy the migration fails ...
0
votes
1
answer
101
views
How to have a repository-type table without FKs?
Is it possible to have a type in Entity Framework Core that doesn't create FKs to every other table that uses it? Creating the DB-Scheme from the C#-model with Add-Migration and Update-Database.
For ...
1
vote
0
answers
53
views
EF Core + Npgsql: "column 'status' is of type application_status but expression is of type text"
I've been struggling for two days with a PostgreSQL enum type issue in Entity Framework Core. Despite all my configuration, EF Core keeps trying to send a string (`text`) to an enum column.
The ...
0
votes
2
answers
82
views
Defining many-to-many with join table foreign key names without concrete c# domain table (shadow join)
I am trying to link a many-to-many relationship without any intermediary class in my domain.
The link is SoundProfiles <-> Switches. They're both not required. The error I get is
One or more ...
0
votes
1
answer
100
views
Entity Framework Core queries in an ASP.NET Core application targeting an Azure SQL database are running with wildly different runtimes
I have a web app using code-first EF Core.
One of the controllers needs to run what should be a simple query (basically SELECT TOP 1 * FROM companies WHERE id = @id; in EF terms,
var data = await ...
1
vote
1
answer
94
views
Unable to create a 'DbContext' of type 'AppDbContext'. The exception 'Object reference not set to an instance of an object.' was thrown
I'm getting this error :
Unable to create a 'DbContext' of type 'AppDbContext'. The exception 'Object reference not set to an instance of an object.' was thrown while attempting to create an instance....
1
vote
1
answer
104
views
How to use expression setters in ExecuteUpdate again in EF Core 10
Microsoft have changed ExecuteUpdateAsync to accept non-expression setters parameter in NET 10. Now it works this way:
await context.Blogs.ExecuteUpdateAsync(s =>
{
s.SetProperty(b => b....
17
votes
4
answers
5k
views
installing dotnet-ef dotnet tool throws error
I’m trying to install the Entity Framework Core CLI tools globally using the .NET CLI command:
dotnet tool install --global dotnet-ef
However, the installation fails with the following error message:
...