Category "linq"

How to translate this SQL into LINQ, with correlated subquery single table

The raw SQL uses correlated subquery for single table, any possibility to translate this with single LINQ Query? SELECT * From dbo.Products AS P1 WHERE SalePric

Group elements of the data set if they are next to each other with LINQ

I have a data set (ex. 1, 1, 4, 6, 3, 3, 1, 2, 2, 2, 6, 6, 6, 7) and I want to group items of the same value but only if they are next to each other minimum 3 t

Linq Nullable object must have a value. errors in .NET 6 and EF Core

I have this code: IQueryable<WinnerClassExtend> dataList = from Class in _context.AllClass join Winner in _context.AllWinners on Class.ClassId equals Win

How to apply filter in child tables using Linq

Net application. I have one entity with child entities. I have to filter based on child entity values. For example in the below query, var sourceProposal = pro

C# Dictionary elementSelector struggles with implicit IEnumerable cast

Simple scenario : var d = new Dictionary<int, List<int>>(); Dictionary<int, IEnumerable<int>> d2 = d.ToDictionary( kv => kv.Key,

Get average of sum of grouped values with LINQ

I have an IEnumerable with fields Name(string) and Amount(ulong). I want to get a single LINQ query to group those elements by Name and then get their sum and a

Filter List inside List Linq

I have list say list of customers and inside each list there is another list of orders Class Customer { int ID, string Name List<Order> orders } Class Or

LINQ script class throwing TaskCanceledException Error

I am working on .NET CORE 6 application along with Entity Framework CORE 7. I have class where I have written LINQ script. This is async method. I am not sure w

How can I skip loop for first and last element of array and set them to constant value?

I would like the loop to start from the second element and to end before the last one. So that I can set the first and last one to constant value. for (int i =

Error when replacing .ToList() calls in with an IQueryable

I'm trying to improve the efficiency of this method and I can't figure out why my "solution" is throwing an error. Here's the existing and working, albeit slow,

What does "object is enumerated" mean in C#?

I've been reading lately articles and documentation about deferred execution, LINQ, querying in general etc. and the phrase "object is enumerated" came up quite

SELECT result map to entity in Dynamic Linq in Entity Framework Core

I have a Linq query which is selecting 2 columns(that can be any 2 from all columns) dynamically based on some condition.I need to map the query result in to be

Ignore global query filter for joined entities

Global query filters are very handy when implementing tenant and soft deletion features. But my problem is is that when i write a query with joins, for instance

How to Sort a Model Based on a Property in IList<T> within that Model

This is a bit more complex than other questions. I have a Model that encapsulates an IList. Within each IList item there are multiple Lists. This makes it VERY

Sort dynamic model with orderby

I am combining 2 tables that I transferred to the dynamic model into 1 table in the cshtml part. And I want to sort that table by a column(OrderBy). How can I d

Entity framework core TPH query across different subtype properties

I'm using EF core TPH inheritance to model some data and I'm trying to write a query that will query across different subtypes. My current attempt at writing a

Linq .Distinct() add extraneous ordering

My entity has a computable geography::point column (represented by DbGeography type in code) When I call a .Distinct() method on query for this entity it adds O

Quickest way to do a [adsisearcher] and store in a hashtable or dictionary collection list

I am using [adsisearcher] to grab AD User info because it's way faster than get-aduser. I am also trying to figure out how to add it into a hashtable or diction

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", "s

How to sort entity model by column name of display model in C# .NET Core using LINQ?

I have a page that displays all users in the table. The front end uses a class that is different from the database model. public class UserDetailsViewDto {