Category "linq"

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

How to use Automapper to project object to Dto in LINQ

I am working on .NET Core 6 along with EF Core. I want to convert Customer and Order object that I have inside LINQ select to CustomerDto and OrderDto using Pro

Can't find single property and navigate related data without IQueryable all properties

I have relational data properties on my objects that I would like to access: public class Person { public ICollection<Address> Addresses { get; private

IQueryable extension to group dynamicly by minutes ...and other

I wanted to create an IQueryable extension to allow other developers to group entities by minutely interval but also by custom group key result. My idea was to

LINQ Expression GroupBy Select First

I've got a question on LINQ Expression. I need to replicate the following lambda: var result = processRevisions OrderByDescending(pr => pr.CreatedAt) G

MAX and MIN on string array in c#

I have started to learn Linq recently. I came across a few inbuild methods like Min() and Max(). The working of these two methods is fine with int[]. But when i

LINQ query returns error "The expected type was 'System.Int32' but the actual value was null."

So this is the query: from c in Contents join cs in DepartmentSharings on c.ContentId equals cs.ContentId select c.PrivateCategoryId.Value When I run this I