23,536 questions
Best practices
0
votes
1
replies
49
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 ...
0
votes
0
answers
68
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 ...
1
vote
0
answers
45
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
1
answer
96
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
80
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....
-1
votes
0
answers
48
views
Respect ConcurrencyToken or ConcurrencyCheck on included Properties in EF Core [duplicate]
Given a class A, and a class B, where class A holds a reference to class B, and where some logic in A depends on some state in B, how can i configure EF Core to make sure B has not changed when ...
Advice
0
votes
5
replies
105
views
C# & EF Core nullable type return vs not found or multiple database rows
I have the following use case: the database contains a row with a nullable column, and I would like to request only that column value from the database for a single row.
This can easily be done using ...
2
votes
1
answer
75
views
How can I solve an EF Core error querying SQLite?
I just got my .Net 9 Maui app working with EF Core and SQLite. I have one row of data in the database that looks like this:
I have a simple query that runs when the app loads. The repository method ...
0
votes
2
answers
72
views
How do I resolve a error global::System.Diagnostics.Debugger.Break(); in a .Net Maui application
I'm trying to configure a new Maui app to use EF and Sqlite following this guide: https://learn.microsoft.com/en-us/dotnet/maui/data-cloud/database-sqlite?view=net-maui-9.0
For a long time I got an ...
1
vote
1
answer
60
views
EF Core - Custom DBFunction - Usage with Linq Dynamic
I have a simple DbFunction to convert a date string column (mm-dd-yyyy) to datetime before ordering. The DbFunction is set up in the DatabaseContext class as follows.
[DbFunction("...
3
votes
2
answers
115
views
How to handle EF Core update + Azure Blob upload transactionally in a single request?
I'm building an ASP.NET Core Web API where I need to upload a file to Azure Blob Storage and update an EF Core entity in a single request.
The challenge is that EF Core supports transactions, but ...
2
votes
1
answer
119
views
.NET / EF Core / AutoMapper causing PostgreSQL "invalid input syntax for type json" error when saving entity
I'm working on a .NET 8 project using Microsoft.EntityFrameworkCore 8.0.7 with PostgreSQL as the database. I have a table that contains a jsonb column, and I'm using AutoMapper to map a DTO to the ...
7
votes
1
answer
205
views
Multiple SUM issue with EF SQL
I'm trying to use Linq to generate a SQL command like this
return await query.GroupBy(x => new
{
Id = x.xId,
...
4
votes
1
answer
301
views
An exception was thrown while attempting to evaluate the LINQ query parameter expression
Have a rather simple LINQ query:
var objectExternalIds = new string[] { "abc" };
var query = from order in Context.Order
join apointment in Context.Appointment on order.Nr equals ...
0
votes
0
answers
56
views
Custom primitive type collection in EF Core (8)
I have a nested entity, defined like this:
entity.OwnsOne(e => e.EncryptedElements, o =>
{
o.ToJson();
o.OwnsMany(x => x.Values, o =>
{
o.Property(x ...
2
votes
1
answer
55
views
EF Core Attach method not updating related entities
The entities are:
public class Department
{
public int Id { get; set; }
public string Name { get; set; }
public IList<Employee> Employees { get; } = new List<Employee>();
}
...
3
votes
1
answer
247
views
How can I project an entity in such a way that it remains filterable on the database?
I am trying to project the result of the following query into EF Core 8 entities:
select foo.*
, (case when hst.Id is not null and foo.OtherColumn = 1 then 42 else null end)
as Bar
...
1
vote
2
answers
237
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
1
answer
98
views
Receiving FOREIGN KEY constraint error when trying to update database in the EF Core [duplicate]
I have the following entities
Film:
using System.ComponentModel.DataAnnotations.Schema;
namespace MyWebAPIApplication.Entities
{
public class Film : Base
{
string Title { get; set; }
...
1
vote
0
answers
87
views
How to access DbSet properties at runtime [duplicate]
I am very new to development with ORMs.
In my project, where I use Entity Framework Core, I want to create a class that would encapsulate whole interaction with database, i.e. through which I would ...
2
votes
1
answer
370
views
How can I automatically apply custom naming conventions for PK, FK, index, sequence and default column values in EF Core migrations?
I am using Entity Framework Core and I want to enforce custom naming conventions automatically for PKs, FKs, indexes, and sequences during migrations.
My naming rules are as follows:
Primary key (PK):...
1
vote
1
answer
461
views
How to correctly configure the MapperConfiguration?
private readonly IMapper _mapper;
public CreateDepartmentRequestHandlerTests()
{
var config = new MapperConfiguration(cfg => cfg.AddProfile(new CreateDepartmentProfile()));
_mapper = ...
1
vote
0
answers
67
views
Microsoft.EntityFrameworkCore.Sqlite TOP and LIMIT SQL syntax error
In Entity Framework Core 9.0.9, the query builder fails with SQLite Syntax
builder.Services.AddDbContext<MyDbContext>(fun options ->
options.UseSqlite(connectionString) |> ignore
It ...
1
vote
2
answers
139
views
Reverse a LINQ to Entities query?
How do I use Reverse to reverse the order of the results of a LINQ to Entities query?
Something like:
var result = dbContext.Users.Where(a => a.Name != null).Reverse();
0
votes
0
answers
88
views
How to add rows to a relationship phantom table in EF core [duplicate]
I want to create a custom admin user from the DbContext, so that when my microservices are started in Docker Compose, an admin user is automatically set up by default when migrations are applied to ...