Category "linq"

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 {

Adding objects to IEnumerable

Im making a basic CSV Reader. Im sepparating the header from the contents using header and data. Now, my lists contain data of the type person.: public

How to validate Date Start and Finish Overlap from a list of items

What I have A list of objects with Id, DateStart and DateFinish. [ { Id: 1234567890, DateStart: new DateTime(), DateFinish: new Date

C# LINQ single query to complete an incomplete model

I have a list of incomplete product models. Everyone is missing an owner and a price. Can these deficiencies be filled with a single query to context? Without t

displaying parent-child elements hierarchically in c#

I have a parent-child structure in my db and I want to list them hierarchically n a C# program: id text parentid 1 A NULL 2 B NULL 5 a1 1 6