25 questions
1
vote
2
answers
247
views
Why let with where clause can't translate to SQL?
I have a code snippet that uses let with a where clause.
private List<string> Example2()
{
var query1 =
from c in _context.Customers
let custPurchases = _context.Purchases....
0
votes
0
answers
43
views
EF Core 9 Scaffolding NPGSQL - attribute tags vs modelBuilder
When I ran a scaffold command on my NPGSQL db with the typical default format I find on the web:
Scaffold-DbContext <connection-string> OutputDir Models -Force
It created all my model classes ...
1
vote
1
answer
95
views
HotChocolate [UseSorting] / [UseFiltering] LinQ conflict with ValueObject
Using HotChocolate v15.1.8 with EF v9.0.7 and Mapster v7.4.0, I encounter a bug with [UseSorting] / [UseFiltering] LinQ conversions which appear invalid when applied to DDD ValueObject or EF complex ...
5
votes
0
answers
224
views
MySql.EntityFrameworkCore: Unable to cast object of type 'System.DBNull' to type 'System.Int64'
I'm trying to build a minimal Api for access to a local MariaDB database and my tech is .NET 9, EF, MySql.EntityFrameworkCore, Migrations (Code First) and MariaDB (XAMPP).
When I try to update ...
2
votes
2
answers
66
views
Join two tables and get only one record of the second table for each record of the first table
I have two model classes; the first contains all the fields of the table which are not multilanguage fields.
public partial class Brand
{
public long BrandID { get; set; }
public string Name { ...
1
vote
1
answer
118
views
EF Core migrations add never completes
I'm trying to generate a migration script for my ASP.NET Core 9 Web API. I have 2 separate database contexts, AdministrationContext and CodebookContext. CodebookContext contains only one entity, as ...
3
votes
3
answers
122
views
EF Core: child's composite foreign key not updated with parent's trigger-generated ID in single SaveChanges
How to use EF Core to manage a composite foreign key referencing a parent record whose ID is generated by a database trigger after insertion?
The parent entity's ID is not available during initial ...
1
vote
1
answer
65
views
SQL query with Entity Framework high logical reads
I have this code which uses Entity Framework to query SQL Server in my .NET 9 project:
vm.LastMatch = _context.Matches
.Include(i => i.HomeTeam)
.ThenInclude(i => i.Venue)
.Include(i ...
-1
votes
1
answer
51
views
I cannot do a scaffold with a few tables with user secrets in my API project in .NET 9
I'm new to ASP.NET Core 9 Web API, I'm trying to do a scaffold with a existing database and using user-secrets follow the Microsoft documentation.
I created my user secret file and my keys something ...
0
votes
1
answer
91
views
No code generators are available in this project
Visual Studio 2022
new Blazor server-side application
.NET 9
I used EF Core Power Tools to import my SQL Server database as a DbContext and model classes.
I used the UI in VS2022 for Add/New ...
0
votes
2
answers
106
views
DataAnnotations being ignored in Blazor server-side .NET 9 page
I have a new .NET 9 Razor page Blazor server-side project.
I used EF Core Power Tools to import my database schema and generate the DbContext and model classes.
I created a MetaData class for one of ...
-1
votes
1
answer
95
views
Entity Framework generating a lot of queries for simple update
I am new to EF and am trying to work out why this simple update of a Transaction record generates 9 identical select queries for the record and then the update query. (I see this debugging in the ...
1
vote
1
answer
454
views
TenantInfo returns null in finbuckle.multitenant with .NET Core
I am trying to configure multiple tenants in ASP.NET Core 8 MVC project.
I am using
Finbuckle.MultiTenant.AspNetCore - v9.0.0
Finbuckle.MultiTenant.EntityFrameworkCore - v9.0.0
Microsoft....
2
votes
1
answer
78
views
Update an existing database with migrations
I have inherited an application that uses Entity Framework Core, along with a dump of its database.
Unfortunately the application did not use EF migrations.
To get it on track I've created a first ...
0
votes
1
answer
57
views
EFCore build a where clause as a string
In Entity framework I could build a where clause as a string.
For example;
var whereClause = "ID > 0 and !Inactive";
pList.AddRange(MyData.Set<T>().Where(whereClause).ReduceCasts()....
1
vote
1
answer
58
views
Extra foreign key created in Entity Framework
I'm working with Entity Framework and configuring relationships between the ConfirmationSkill, Skill, and Qualification entities. When I create a migration, an extra foreign key QualificationId ...
0
votes
1
answer
204
views
EF Core FirstOrDefault returns null even if entity exists
I am facing an issue where I cant fetch an entity when using .FirstOrDefaultAsync() with a GUID as the primary key.
If I fetch all entries first and then run .FirstOrDefault it works.
The entity in ...
1
vote
1
answer
70
views
EF Core finding attribute via convention that I don't want it to
I have a class library representing my EF Core 9 database. That library includes a NuGet package of attributes that are set on the model. It's used to configure the generation of PUML files at ...
-1
votes
2
answers
665
views
EF Core 9 : the database operation was expected to affect 1 row(s), but actually affected 0 row(s)
I am using DDD architecture and the following code changes the aggregate root (basically adds a comment which is an entity to the aggregate root).
public sealed class AddCommentToPostCommandHandlers : ...
0
votes
1
answer
244
views
Ignoring a base type in Entity Framework Core 9 code-first
I typically use the following interfaces for EF Core entities (.NET 9, EF Core 9):
public interface IEntity
where TEntity: class, new()
{
// Identity column.
public long Id { get; set; }
...
0
votes
1
answer
284
views
EF Core 9 .HasConversion
I am trying to follow DDD in a new project im working on and have run into an issue when it comes to configuring one of my ValueObjects.
I have the following AggregateRoot
public sealed class Event : ...
0
votes
0
answers
531
views
Update .NET 8 app to .NET 9 / EF Core 9 fails: "Method not found: void Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer..ctor"
We recently started updating our existing .NET MAUI App from .NET 8 to .NET 9. Within this process, we naturally updated all our EF Core references to EF Core 9 as well. Now, the build of the app ...
0
votes
0
answers
44
views
EF Core 9, inserting into a MySQL table with Composite Unique Constraint Best practice? [duplicate]
I'm working with a MySQL table that has a composite unique constraint on two columns (column1 and column2), like this:
CREATE TABLE example_table (
column1 INT,
column2 INT,
column3 ...
5
votes
1
answer
463
views
After migration to .NET 9, I have problem with `string.Join` inside Select statement
Previously, when I used .NET 8, I could use String.Join inside the Select statement for an IQueryable, as shown in this code:
var receiveTransactions = await repository.Context.Set<...
4
votes
2
answers
4k
views
Unable to create DbContext due to GetDatabaseLock method missing in Npgsql EF Core 9.x
I'm working on an ASP.NET Core project using Entity Framework Core and Npgsql for PostgreSQL. I'm trying to create a DbContext to manage my database, but I'm encountering the following error when I ...