Linq to Entities - SQL "IN" clause

In T-SQL you could have a query like: SELECT * FROM Users WHERE User_Rights IN ("Admin", "User", "Limited") How would you replicate that in a LINQ to Entities query? Is it even possible?

How to use LINQ to select object with minimum or maximum property value

I have a Person object with a Nullable DateOfBirth property. Is there a way to use LINQ to query a list of Person objects for the one with the earliest/smallest DateOfBirth value? Here's what I...

Count matching characters between two strings using LINQ

A friend asked me how to improve some code with LINQ. How would you do a character by character comparison between two strings to count the number of matches at an index? Here's the original code,...

How do I concatenate two arrays in C#?

int[] x = new int [] { 1, 2, 3}; int[] y = new int [] { 4, 5 }; int[] z = // your answer here... Debug.Assert(z.SequenceEqual(new int[] { 1, 2, 3, 4, 5 })); Right now I use int[] z =...

Linq find all with certain type

Is there a way to find in a List all items of a certain type with a Linq/Lambda expression? Update: Because of the answers, I realize the question wasn't specific enough. I need a new List with...

linqpad hide specific column or restrict row to single line

ATable.Dump() in linqpad returns the whole ATable. However, ATable.Single().MassiveColumn contains too much data and it fills up the whole results page. Is there a way to either: Write this more...

C# Array.Contains () compilation error

I'm trying to use the Array.Contains () method in C#, and for some reason it's failing to compile, eve though I believe that I'm using C# 4.0, and C# should support this in 3.0 and later. if (!...

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression

I'm migrating some stuff from one mysql server to a sql server but i can't figure out how to make this code work: using (var context = new Context()) { ... foreach (var item in...

C#: Chained Linq methods and casting

I have a little game, where I implemented some collision detection. Now I want to get a list of all items of a specific type, which are colliding with the current "Entity" object. I want to do...

How to convert PropertyInfo to property expression and use it to invoke generic method?

How to convert PropertyInfo to property expression which can be used to invoke StructuralTypeConfiguration<TStructuralType>.Ignore<TProperty>(Expression<Func<TStructuralType, TProperty>>...

Cannot convert IQueryable<T> AsEnumerable because T has a Guid property

I have the following EF class: class Product { public Guid ProductGuid { get; set; } public string ProductName { get; set; } } derived from a DB class where ProductGuid is a...

linq-To-Sql: filter with enum(flags)

I have a enum: [Flags] public enum EmailType { PasswordRecovery = 1, Activation = 2, SendTicket = 4 } For example, in a table we have value equals 3 that means - PasswordRecovery,...

what does a linq query return when no results are found

i'm using a query to see if a user already exists in the database. if it finds a user, it adds it to the list (not database), and presents a message. if the user does NOT already exist, the...

LEFT JOIN in LINQ to entities?

I'm trying out LINQ to entities. I have a problem with the following: I want it to do this: SELECT T_Benutzer.BE_User ,T_Benutzer_Benutzergruppen.BEBG_BE FROM T_Benutzer LEFT JOIN...

Is Select optional in a LINQ statement?

I was looking over some LINQ examples, and was thereby reminded they are supposed to have a "select" clause at the end. But I have a LINQ that's working and has no "Select": public...

The incoming request has too many parameters. The server supports a maximum of 2100 parameters

I have this seemingly simple linq-to-sql query that searches some data in several columns; something like this: List<long> TheTableIDs = list of IDs (sometimes more than 2100) var QueryOutput =...

How to get SecondOrDefault?

I have a simple linq lambda statement Interactions = new BindableCollection<InteractionDTO>(ctx.Interactions.Where(x => x.ActivityDate > DateTime.Today) .Select(x => new InteractionDTO { ...

How can I solve this "System.Data.Entity.DynamicProxies" error

I am new to Linq and EF Code First and came across an issue that I just can't figure out. I am developing a proof of concept examination program using ASP.Net Web Forms, EF Code First and Linq. ...

Linq query with list of flags

I'm trying to get a list of records from data base using Linq query. public void Main() { var filter = new Filter(); filter.ReceiverState = new List<DocumentState> { DocumentState.Completed...

Join three tables with Entity Framework

I have these three tables. I wrote my own SQL code but I can't convert it for List<>. Can you help me please? SQL output: And here is my SQL code: Select H.HastaAdSoyad, R.RandevuTarihi,...

LINQ compare string and DB column type 'text'

This is my error message The data types text and varchar are incompatible in the equal to operator. My code is something like var result = db.Table.Where(x => x.columnA == "A").ToList(); I know...

Why use .ToList after .Include in Eager Loading

This might be easy, but I was wondering why whenever using the process of eagerly loading that .ToList() has to be used after .Include()? I know that eagerly loading allows for the loading of...

Entity Framework Lazy and Eager loading returns System.Data.Entity.DynamicProxies.PropertyName

I am learning Entity framework using Code First approach. I have two clases with a relationship of one to many: public class Product { [Key] public int ProductID { get; set; } public...

How to filter tolist query results based on a foreign key in ASP.NET MVC

I have two Classes Task & User. I want to be able to filter the tasks based on the value of the User class attribute "Name". public class Task { [Key] public int ID { get; set; } ...

The type arguments for method Queryable.OrderBy cannot be inferred from the usage

I am try to create a common extension method which sorts list of object by a specific property. I am getting the below error for my code. The type arguments for method Queryable.OrderBy cannot be...

EFCore 2.2 No mapping to a relational type can be found for the CLR type 'Expression[]'

I have a project that used to use DBML as the ORM for getting data out of our database. We are in the process of replacing this DBML with Entity Framework Core 2.2.6 (unfortunately the most recent...

EF Core 2.2: Add timezone conversion to a datetime2 column on select, groupby and/or where (Modify/enrich property mapping on a query)

First things first, what I'm trying to do is quite similar to what is explained in this question, even the solution by @jeremy-lakeman would fit but seems it only works on +EF Core 3.0. I would...

C# Linq ANY vs ALL - Performance

I am trying to figure out how does ANY and ALL work in Linq. Lets say I have 100k records in a list. Which one should perform faster? if(recordsList.All(r => r.Deleted)) {...

.net6 & MoreLinq : Call is ambiguous between System.Linq.Enumerable.DistinctBy and MoreLinq.MoreEnumerable.DistinctBy

Recently I upgraded one of my projects to use .NET 6. Earlier I was using MoreLinq library to use DistinctBy() to apply it on the specific property. Now as I upgraded TargetFramework to .NET 6,...

Calculate max on a sliding window for TimeSeries

Input: public class MyObject { public double Value { get; set; } public DateTime Date { get; set; } } Method to generate test objects: public static MyObject[]...