All Questions
Tagged with linq entity-framework-core
1,988
questions
-1
votes
1
answer
56
views
Equals method never called by LINQ expression [duplicate]
My data class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using static iText.StyledXmlParser.Jsoup.Select.Evaluator;
...
-1
votes
0
answers
63
views
Performance degradation of linq query in C# after .NET Core upgrade to 8 [duplicate]
I have the simple linq query in my .NET Core C# app. We have upgraded from .NET Core 3.1 to .NET 8.
My query is as follows:
Decimal[] cks = mem.Select(a => Convert.ToDecimal(a.KEKE_CK)).ToArray();
...
0
votes
1
answer
59
views
Entity Framework Core : Include not working for many-to-many relationship
I'm having trouble with .Include() not working for many-to-many relationships in Entity Framework Core. My setup works fine for one-to-many relationships, but the related entities are not being loaded ...
0
votes
0
answers
78
views
Linq query DateOnly fields returning results on comparing dates
I have this linq query request as:
var test = (...
where ...
&& test.SL.Any(line =>
line.ServiceCode == serviceCode
...
0
votes
0
answers
55
views
Is there a way to convert a LINQ expression to another LINQ expression?
My repository class has a few methods for operations with the database. I recently developed the FindAsync() method, which allows you to grab only a few rows from the database based on an expression.
...
-1
votes
0
answers
74
views
Join in-memory list and DB table in .net 8
I have a code that is working in .Net 3.1 and we have upgraded to .Net 8 and as part of that I have converted Nuget package Microsoft.EntityFramework.MemoryJoin to 0.8.0 and I observed the in-memory ...
2
votes
2
answers
80
views
How can I reuse the logic in a .Include.Where() call while working with Entity Framework Core in .NET?
I am writing a database query using LINQ in .NET and I want to be able to not duplicate the code I put in my Where method calls.
I want to return Blogs that have fresh Comments, and want to filter ...
0
votes
0
answers
34
views
EF Query Translation failure if using constructor but not if using property initialization
When performing a somewhat convoluted query I get a "could not be translated" exception if I am selecting into a class that uses a constructor. Oddly I get a success if I use the same class ...
2
votes
2
answers
52
views
How to filter a query based on row number using LINQ with Entity Framework
I have the following query in MySQL (version 8+)
SELECT MachineId, TotalProduction
FROM (
SELECT MachineId,
TotalProduction,
ROW_NUMBER() OVER (PARTITION BY DATE(InsertedAt) ...
-5
votes
0
answers
79
views
EF Core comparing DateTime performance. SQL CONVERT(Date) vs SQL DATEPART
I have a DateTime column called TimeStamp in my database table. It is indexed.
Which of the queries below gives me a better performance? QueryA or QueryB?
var dateOnly = new DateOnly(2024, 01, 01);
...
0
votes
1
answer
54
views
EF Core 8 : single value objects. Error on linq
In EF Core 8, I'm trying to do this query (Active is a simple value object of type bool):
return await _dbSet
.Where(e => e.Active.Value)
.ToListAsync();
And I get:
...
0
votes
1
answer
48
views
Entity Framework Core: Passing a function to a Where and doing a Select will construct the object? [duplicate]
I am running into a very confusing issue with querying data in EF Core, and hoping that I can find the answer here.
I have School and Student entities that are mapped to the tables with the same name ...
0
votes
0
answers
56
views
Translate expression bodied member to SQL so it can be used in LINQ where clauses?
Is it possible to write an extension to EF Core that tells it how to translate expression bodied members (or methods) to SQL so a getter/method can be used in where-clauses?
What I would like to ...
1
vote
1
answer
94
views
C# cannot use .Any() when build Expression for querying with EF core
I'm trying to build an Expression<Func<T, bool>>:
public static Expression<Func<T, bool>> CreateAny<T, TAnother>(
Expression<Func<T, IEnumerable<TAnother&...
0
votes
1
answer
50
views
How to test a method that calls a persistence method returning IQueryable
I read in a few places that it's a good practice for a method that calls the database to return IQueryable because it allows extending queries in services using methods like Select, Where, etc., and ...