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
14 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
11k views

VB.NET: LINQ Query on DataTable - WHERE Id >=0

Hey people, I am bugfixing an application for some friends of mine. They are using VB.NET and Windows Forms, while I am in team C#/WPF/ASP. My knowledge about LINQ is also very limited even if its ...
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 ...
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 = ...
3 votes
3 answers
3k views

How to solve a SonarQube S3267 warning, "Loops should be simplified with "LINQ" expressions"

Consider the following code (which is a simplified version of my actual code): static void Main(string[] args) { string[] data = { "one", "two", "three", "stop&...
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>? ...
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 ...
55 votes
5 answers
33k views

Moqing Entity Framework 6 .Include() using DbSet<>

I'd like to give the background to this question. Skip if you like. For quite a while I've paid close attention to the on going debates on stackoverflow and elsewhere regarding testing of code as it ...
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
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 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; ...
0 votes
2 answers
3k views

Find Matching Fields of List and IEnumerable objects in C#

There is a long and tedious way I could perform the task I want to accomplish, but I am thinking there must be a way using Linq or some other neater more efficient technique to achieve this. I have a ...
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&...
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 ...
36 votes
4 answers
40k views

IQueryable order by two or more properties

I am currently ordering a list of custom objects using the IQueryable OrderBy method as follows: mylist.AsQueryable().OrderBy("PropertyName"); Now I am looking to sort by more than one ...

15 30 50 per page
1
2 3 4 5
5780