“Tasks” table: “Task History” table: Sql query: Which tasks were completed in the last 30 days? Q: What is the equivalent LINQ expression for this SQL query? Answer This query should do what yo want:
Tag: entity-framework-core
RawSQL and auto-generated keys in EF Core 3.1
I have a Model with a Guid primary key. I want the Database to generate a key on insert so I added the following annotations: Now I expected that inserts with RawSQL wouldn’t expect a primary key, however the folllowing statement doesn’t work when executred through ExecuteSqlRaw: An error is caused by the DB about a non-nullable primary key. Explicitly
How to get output parameter results and query result from stored procedure?
I have this stored procedure which I call from C# using Entity Framework Core using a DbContext When I call the SP from code, the output parameters are empty. How to get the output parameter values in code? When I call the SP directly from SQL the output parameters are populated correctly. Answer You’re missing the OUTPUT keyword when building
Why is DbUpdateConcurrencyException thrown?
I am using an SQL server and I have a table whose purpose is to hold a tree-like structure: The “Path” column value is generated by INSTEAD OF INSERT, UPDATE trigger. I am using EFCore 3.1 and each time I try to add a record into the table, I get DbUpdateConcurrencyException thrown. What am I missing – how do I
PostgreSql and EF – Getting ‘duplicate key’ error while doing ‘ToDictionary’ after grouping
Here is my query. UserName column is citext, having non-unique index on it. var logs = Db.Logs .GroupBy(x => x.UserName) .ToDictionary(g => g.Key, g => g.Max(m => m….
LINQ for getting the 5 latest records for each distinct name
I have been trying to get the 5 most recent records from a database with distinct names from the “Name” Column. Meaning I want the 5 latest records for each of the unique names in the table. Here is a sample table: I would expect the latest 5 Bob records (out of the 6 ), the 3 Chris records, and
FromSqlRaw injection EF Core 3.0
I am wondering how safe the fromSqlRaw method is. I am doing the following in my code, where the person id is a parameter from the method itself: Is this code safe to SQL injection? And is there other security vulnerabilities that I should know of when using this? Answer Use proper parametrization for your input. After clarifications in comments,
SELECT the patients that have similar disease name EF core 3.1
I have the following tables Patients ID PatientName PatientIDNumber —- ————- —————– 1 Jo 411420607 2 Mark 206047758 …
Entity Framework Core 3.0 .Include call taking 10x more time
I reviewed almost everything online but couldn’t get it work in a reasonable time. Entity Framework Core 3.0 .Include call is taking 10x more time than calling the individual tables separately and then mapping them in C# code. I have two tables product and productimages, where product productimages is a collection inside product. Now when I chain the call with
dotnet Entity Framework INSERT SELECT FROM other table
I am not an expert on databases and SQL. I am developing a dotnet core application using the Entity Framework to access a (postgresql) database. I have the following tables with the following columns: …