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]
47
questions
-1
votes
0
answers
26
views
Improving performance of contains method in ASP.NET MVC web application with large dataset
I have an ASP.NET MVC web application using C#, Visual Studio, and SQL Server. This is my code:
if (!string.IsNullOrEmpty(Name))
{
query = query.Where(x => x.PatientName.Contains(Name));
}
The ...
0
votes
1
answer
41
views
2 LINQ queries use the same joins. Is there a way to "factor out" the joins and gain a performance benefit?
Here are two example queries:
var queryA =
from t1 in context.T1
join t2 in context.T2
where
tl.colA == desiredColAValue
select new ObjectA(valuesFromQueryA)
;
var queryB =
...
2
votes
2
answers
39
views
How to handle the possibility of expected null properties in a LINQ were clause?
Consider the following C# Code Fragment:
public class Person
{
public int Id { get; set;}
public string? Name { get; set;}
public string? Description {get; set;}
}
List<Person>? ...
0
votes
0
answers
60
views
How do I set SQL Provider in C# Linq
I changed the default collation of my SQL Server 2022 database (and all string objects that already existed) to Latin1_General_100_CI_AS_SC_UTF8.
Unfortunately, Linq seems unable to handle this ...
-1
votes
1
answer
41
views
Insert prefix in a Xml string [duplicate]
I need to be able to write this Xml string:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:a="http://www.w3.org/2005/08/addressing"
...
1
vote
1
answer
54
views
C# linq Include OrderBy
I need some help sorting data by Included data. In the example below, I am returning a purchase order where I want to sort the purchase order line items by the line item id.
return await context....
-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
vote
4
answers
46
views
Apply Group by to dictionary value
I have a Dictionary which key of string type and value of list of integer type, like this:
Dictionary<string, List<int>>.
Lets say I add elements to it:
Dictionary<string, List<int&...
-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
0
answers
93
views
Why this C# code runs slow if the loop is more than 30 times? [closed]
int range = 20;
var test = Enumerable.Range(0, range).Select(i => new Section { Id = i, Value = i }).ToList();
var result = RemoveEvenNum(test);
foreach (var section in result)
{
Console....
1
vote
1
answer
52
views
LINQ group with list inside shows only the first row
I have a view in the v_PortalProprietario database that returns in each line the name of the owners that are repeated and the accounts (Acertos) that are unique. I would like to make a query in Linq ...
0
votes
1
answer
59
views
Convert List<Task<T>>> to List<T> [duplicate]
I have this variable that should project and return a list of AttachmentRequestModel as follows :
var mappedAttachments = recordAction
.PPAttachments
.Select(async x => new ...
0
votes
2
answers
55
views
How to join tables and group the results using LINQ?
I have a table of Products and a table of Product_Images with a one to many relation (one product can have multiple images) and I am trying to retrieve all products with their related images. So far I ...
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
1
answer
54
views
Pagination on the result from multiple collection .net
I am trying to add offset pagination( input is pagesize and limit) on combined result which is aggregating multiple collections. Earlier I had only limit on the reponse. Below is the code for the API ...