Questions tagged [linq]
Language Integrated Query (LINQ) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages. Please consider using more detailed tags when appropriate, for example [linq-to-sql], [linq-to-entities] / [entity-framework], or [plinq]
86,700
questions
0
votes
1
answer
46
views
Fetch the Name based diff version for same Service and Function
Here is my Json object .
[
{
"Id": 1,
"Name": "Asset A",
"Version": 1,
"Function": "Song",
"Service": "Song"
...
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) ...
0
votes
1
answer
60
views
Chaining of multiple LINQ conditional Orderby(Descending) and ThenBy(Descending) clauses
I've encountered a problem when trying to implement sorting logic:
Imagine a Person model that consists of multiple fields, alike:
public class Person
{
public string firstName { get; set; }
...
-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
2
answers
75
views
Making retrieving data from database faster
last time L had that type of retrieving data:
var users = _context.Users.AsQueryable();
var userDtos = users.Select(user => new UserGetDto
{
Id = user.Id,
Name = user.Name,
SurName = ...
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
1
answer
62
views
C# Datatable contains duplicate row- Need to find the duplicate
I have data table in c# and it contains more columns and rows I need to find the duplicate row and show the row number. Data table always comes with undefined column names it’s not fixed columns....
0
votes
1
answer
59
views
how should I be using PredicateBuilder from LinqKit C#
I have a quite complex Linq query that worked fine in standard Linq. However, I need to change the way the query gets built and depending on user selection include 0:n 'Or' statements in the query.
So ...
0
votes
1
answer
33
views
Serialize an xElement with namespaces and text values
This is the first time I've used System.Xml.Linq to serialize. I have learned many things especially on this site, but now I can't solve a problem, perhaps trivial, but I can't.
I need to create this ...
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 ...
0
votes
0
answers
19
views
Use Mutation in GraphQL with Chocolate
How can I solve the next error in GraphQL and C#, Query, Models, etc, works, but no Mutation, I don have any Idea for fixed it this, all code is correct but contnues ask me about Errors and about ...
0
votes
0
answers
52
views
How can I dynamically create my Linq statement [duplicate]
I've been searchng for an example to create my linq statement dynamically, but I've not managed to find an answer.
IQueryable<Booking> booking;
I then do an intial Lambda returning a number of ...
0
votes
1
answer
84
views
How to search for value in object[,] using LINQ
I have a large matrix that represents tabular data, and I need to find the row where a specific value exists in the first column. Here is a simplified version that give the same compile-time error, ...