Skip to main content

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]

0 votes
0 answers
17 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 ...
hud. 's user avatar
  • 170
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 = ...
rob.loh's user avatar
  • 13
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>? ...
William Holmes's user avatar
0 votes
0 answers
59 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 ...
awba's user avatar
  • 1
-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" ...
Modest's user avatar
  • 13
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....
michael's user avatar
  • 35
-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; ...
janci's user avatar
  • 403
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&...
sst's user avatar
  • 23
-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(); ...
anvesh's user avatar
  • 77
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....
Hui Jin's user avatar
  • 19
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 ...
dgbrazil's user avatar
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 ...
Voice Of The Rain's user avatar
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 ...
SeptimaEspada's user avatar
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 ...
shuvo's user avatar
  • 174
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 ...
Divya Vyas's user avatar
0 votes
3 answers
79 views

Sequence contains no elements in LINQ

In the code shown here, I am getting an error in LINQ: Sequence contains no elements When the reason column contains data, it is throwing this exception. Please suggest how to handle this exception. ...
user2432361's user avatar
0 votes
3 answers
58 views

Entity Framework C# join with one column only from second table

I have a join in Entity Framework connecting the Order and the OrderItem tables. All orders will have multiple order items. I'm trying to return all the orders, but only the orderItemStatus column ...
Sherry8212's user avatar
-2 votes
0 answers
29 views

Npgsql.PostgresException: '42703: column c.UserId1 does not exist [closed]

var list = _user.FindAll( filter, NoTracking: true, hideDeleted: true, take: data.Length, page: data.Page, orderBy: data.OrderString); Error: Npgsql.PostgresException: '42703: ...
mery's user avatar
  • 1
-1 votes
0 answers
53 views

Linq query for same table parentId

This is my table structure: enter image description here Now I want to result like this: enter image description here I wrote a SQL query shown here, and it returns results as expected, but I want it ...
Anrorathod's user avatar
0 votes
1 answer
30 views

The cast to value type 'System.Int32' failed because the materialized value is null LinQ

I do have below query, (from p in _dbContext.MyTable where batchIds.Contains(p.BatchId) select new ParticipantToRespond { ParticipantId = p.ParticipantId, TeamId = (p.TeamId ??...
sampada salunke's user avatar
1 vote
1 answer
49 views

How to delete the rows of datatable1 having different ID while compare with the datatable2

Given the first data table having master data and the second table having the needed data IDs, I need to delete the rows from the first table which are not present in the 2nd table. I am trying to use ...
Dev's user avatar
  • 1,681
-1 votes
0 answers
72 views

when converting the code from csv to xml, the text does not transfer from the file

When running the code, a terminal is launched in which all the text from my file is shown, but then when opening the file values is not there. What could be wrong. About my code : I try to convert CSV ...
Shiryazdan Ushurbakiev's user avatar
0 votes
0 answers
28 views

Use some kind of helper function In EF Select query to make subquery [duplicate]

I have several tables that handles different kinds of translations for my entities and those tables to linked via relations to other entities. I use subquery to directly access translations tables ...
user3408420's user avatar
0 votes
1 answer
49 views

How to group text to lines if there is small difference in Y position

Using PdfPig to read text from order PDF as described in Get Text Line By Line From PDF using C# answer static void GetWordsInReadingOrder(UglyToad.PdfPig.Content.Page page, StringBuilder builder) ...
Andrus's user avatar
  • 27.3k
-1 votes
1 answer
61 views

LINQ query where clause in list

I am trying to limit the data returned via a repository using the where clause based on a list of values. I have a PurchaseOrders entity where I want to return all purchase orders that have an ...
michael's user avatar
  • 35
0 votes
3 answers
78 views

Selecting 2 Elements from XML

I am having a lot of trouble translating examples I am finding into use with XML. Starting with this (a very cut down version of the whole XML file) <?xml version="1.0" encoding="UTF-...
jc508's user avatar
  • 93
0 votes
2 answers
55 views

LINQ - Get key-value pairs for dictionary with lists

Let's say I have: Dictionary<string, List<string>> test = new() { { "animal", ["cat", "dog"] }, { "fruit", ["banana", "apple&...
AppleMoose's user avatar
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 ...
Jesus's user avatar
  • 445
0 votes
2 answers
45 views

How to use Enumerable.Aggregate without getting CS0411 error

There are two DTO records: public record struct DateHour(int Hour, double? Value); private record struct HourSnapshot(uint TotalSeconds, double? Value); I have another method which works with enum. I ...
Anthony Voronkov's user avatar
3 votes
1 answer
71 views

Remove In Nested Loops (Remove Inside Foreach) [closed]

These are my entities: public class Permissions { public string PermissionName { get; set; } public List<Controllers> controllers { get; set; } } public class Controllers { public ...
Yasim Yasin's user avatar

15 30 50 per page