Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
0 votes
0 answers
15 views

How to create a dyamically lambda expression, to feed a Where.() on a List<CustomClass>

Hello i have a List of this custom class of mine (List<ClassePerLifoFifoGestioneInner>). The class i built like this: public class ClassePerLifoFifoGestioneInner { public int ...
Scvmbi's user avatar
  • 1
0 votes
2 answers
97 views

Convert Expressions C# with existing Queryable methods

I need to append methods to an existion experssion and combine them into a new resultExpression. Expression<TSource, IQueryable<TResult>> sourceExpression; Expression<TSource, int, int, ...
Vlad Nan's user avatar
3 votes
0 answers
433 views

how to remove a condition from an expression IQueryable object in C#

I have an IQueryable object sth like; IQueryable<People> query = DemoData.Where(x => true); query = query.Where(p=> p.Nation == Nation); // query indicates people from a Nation now. /* ....
Ali CAKIL's user avatar
  • 428
1 vote
2 answers
105 views

Given an expression to be consumed by the "Where" method of an IQueryable, a nested "Any" method will accept a "Func<>" only if it's defined inline

Keep in mind that the inner Any method accepts a Func<MyChildEntity, bool> argument, not a Expression<Func<MyChildEntity, bool>>. I think I'm aware of the difference between the 2 (...
Carlo Arnaboldi's user avatar
1 vote
2 answers
343 views

How can I convert lambda expression with C#?

I need IQueryable extension method for my custom query. Example method and I want be result is below. How can I do this ? Input => .Where(x => x.Id == 1) .FilterContent<ProductTranslate>(x ...
brk.gs's user avatar
  • 15
0 votes
2 answers
90 views

IQueryable Lambda Expression for every Nth date

I have a calendar table that contains a series of dates, and I'm trying to write a query that gives me every N dates. I can do this in SQL without difficulty, but when writing it in a IQueryable with ...
Victoria Berger's user avatar
0 votes
2 answers
184 views

Apply inner expression filter on IQueryable

Suppose I have the following objects: public class Source { public string Name; } public class Target { public string Name; } public class Result { public Source SourceObj; public Target ...
Timur Ginesin's user avatar
1 vote
1 answer
3k views

How to convert LambdaExpression to Expression<Func<T,bool>> in C#

I have the below code that generates LambdaExpression at run time based on my SearchTerm inputs. I'm trying to build a dynamic where clause. However I'm stuck at how to convert from LambdaExpression ...
fingers10's user avatar
  • 7,867
1 vote
1 answer
494 views

Get lambda expression from where clause or IQueryable/IEnumerable

Is there a way to get the expression from known where clause, then pass it to other Where(<expression>) clause? I'm on .NET Core 3.0 preview with EF Core preview. Included linq and linq ...
Max94's user avatar
  • 125
1 vote
2 answers
2k views

Filter IQueryable which contains (%like%) any of the items in the List<string>

I want to filter an IQueryable/List using List without hitting the database. The IQueryable result should include all result containing any of the strings in the List and the length of the list is ...
snewk's user avatar
  • 11
1 vote
0 answers
23 views

How to use multiple field selectors in an IQueryable extension that builds an expression [duplicate]

I've created an extension method on IQueryable that allows me to more succinctly filter on records where a date is between two specified values, like this: query = query.WhereValueBetween(x => x....
Govert's user avatar
  • 13
2 votes
1 answer
5k views

IQueryable does not contain a definition for 'Select'

I'm trying to create a method that will take in a Func<Object1, bool> as a where clause and perform a Select on it as a subquery. This seems to be causing an error on the IQueryable where it ...
Clavaat's user avatar
  • 87
2 votes
1 answer
335 views

Why does this Linq method accepts parameters of type Expression

I found this method in other post, and I pretty much understand what's going on, except for the 4th line: public static IQueryable<T> OrderByMember<T>(this IQueryable<T> source, ...
The One's user avatar
  • 4,784
1 vote
0 answers
737 views

What IQueryable.Provider.CreateQuery<T> will provide?

I want to create something like remote Linq expression executor with EF core 2. At first, user send a request to the server 2) server will generate an expression which can be execute on user demand ...
Mohammad's user avatar
2 votes
1 answer
662 views

Wrap a Expression<Func<T,bool>> with a type cast

My repository returns entities derived from a common base class class BaseClass { public int Id { get; set; } } class MyClass : BaseClass { public string Name { get; set; } } class ...
user1859022's user avatar
  • 2,685
0 votes
2 answers
1k views

C# Expression composition [duplicate]

Say I have two classes: public class Parent { public Child Child { get; set; } } public class Child { public string Name { get; set; } } And I want to write a function that filters Parents by ...
Michael Wilson's user avatar
4 votes
0 answers
620 views

How to dynamically create IQueryable<T> from list of column names

I have 2 entities, Country and City. A Country can have many cities. I want to achieve the following: IQueryable<Country> query = myContext.Countries .Select(co => new ...
Azia Stephane Lobognon-Naki's user avatar
1 vote
1 answer
245 views

Lambda expression to SQL query without external DLL

I'd like to convert a lambda expression into a SQL query. To do this, I have done: public class User { public string FirstName {get; set;} public string LastName {get; set;} public string ...
Alex's user avatar
  • 43
0 votes
0 answers
264 views

How to apply an expression to an IQueryable for Entity Framework?

I've got a dictionary of lambda expressions: private readonly Dictionary<SortSpec, Func<IQueryable<CompanyData>, IQueryable<CompanyData>>> _sortHelp = new Dictionary<...
Volker's user avatar
  • 1,805
1 vote
1 answer
874 views

#Order by Not Null using expression Extension linq

I have a custom IOrderedQueryable function as below. public static IOrderedQueryable<T> OrderBy<T>(this IQueryable<T> srcQuery, string orderColumn, bool isAscending) { var type = ...
rockingmeister's user avatar
2 votes
1 answer
2k views

How to combine N amount of expression trees with OR/And operators

Currently I have an expression tree that represents a MONSTOROUS Lambda in the form of Expression<Func<Project, bool>> I did this to replace a repetitive amount of looping with Linq. Here ...
Train's user avatar
  • 3,476
1 vote
2 answers
348 views

How do I abstract out the select in this Entity Framework IQueryable query?

I have the following Entity Framework queries: var items1 = items.Select(x=> x.Prop1) .Select(...).OrderBy(..).ToArray(); var items2 = items.Select(x=> x.Prop2) ...
heyNow's user avatar
  • 886
3 votes
1 answer
2k views

Dynamically build IQueryable Select clause with fieldnames in .NET Core

I am wanting to extend my IQueryable to take a List of fieldnames and only return those columns into a dynamic collection. Essentially I want to implement the "Select" with passed in field/column ...
KickinMhl's user avatar
  • 1,428
4 votes
1 answer
2k views

Is it possible to get the predicate (Expression<Func<T,bool>>) used on an IQueryable<T> and apply it to another Lambda function?

I have the following issue: I get an IQueryable<T> from LinqToQueryString This IQueryable<T> is used to query MongoDB The IQueryable<T> is used to return paged dataset as well as ...
JDeVil's user avatar
  • 487
0 votes
1 answer
88 views

Why does C# compiler allow use of a dynamic operation in expression tree if ToList or ToArray is called

Please note: I am aware that there are many related to the main error message discussed here but I could not find any post that discusses my question. Therefore, please be kind to read to the end ...
Menol's user avatar
  • 1,338
-3 votes
1 answer
585 views

Can you add a Where() to an IQueryable when the field is not in the selected output

Suppose I have a 2 table join in a function that returns an IQueryable, but the output is a named type that is neither of the two tables: var qry = from p in Persons join h in Hobbies on p....
Randy Magruder's user avatar
0 votes
1 answer
36 views

Finding the appropriate return type for linq to SQL generic functions

I'm trying to build an extension method to IQueryable which accepts a sort direction as an argument. I want to be able to apply this method to SQL server queries with EF. Here is what I have so far: ...
Jacob Horbulyk's user avatar
3 votes
2 answers
16k views

c# Lambda Expression - Get property value from string [duplicate]

Consider following lambda expression: IQueryable<Product> query = query.Where(x => x.ProductName.Contains("P100")); I need to convert above code something like this: IQueryable<Product&...
Rahul's user avatar
  • 2,711
1 vote
1 answer
2k views

How to remove items from IQueryable anonymous type

var flowers = from f in c.Product select new { f.ProductID, f.Price, ...
caleb wheeler's user avatar
1 vote
3 answers
67 views

Building query to filter on OR conditions

I'm trying to build a query where I filter news based on themes. Every news item can have several themes. When I filter I want to get every news item that has any of the themes I filter with but what ...
Andreas Fredriksson's user avatar
3 votes
1 answer
509 views

How to get a function that returns an expression to be called rather than interpreted as an expression

I'm working with SharePoint CSOM. This uses a query language based on expressions to specify what data to retrieve. The system I am working on makes several different queries, but they all need to ...
Jack A.'s user avatar
  • 4,413
0 votes
1 answer
589 views

Apply a dynamically-built expression on non-generic DbSet

I have the following scenario: I have an unknown at compile time DbSet, which I get it via its type like: DbSet entities = _repository.Context.Set(myType) I have a dynamically-built expression of a ...
Tamas Ionut's user avatar
  • 4,410
0 votes
1 answer
1k views

Execute IQueryable after it's being done building

I want to build filters on IQueryable depending on user input and execute the query only at the end. I'm trying to understand concept behind and if this is going to work as expected. Will the query ...
skmasq's user avatar
  • 4,511
0 votes
1 answer
937 views

Lambda Linq Iqueryable group - add another grouping

I have a method that I use for generating a summary report, based on the options a user selects in pick lists, to count the number of a type of test that is completed in a region, with subset ...
Jennifer S's user avatar
  • 1,439
2 votes
3 answers
1k views

How to convert/cast IQueryable<AnonymousType> to IQueriable<Strong Typed Object> with lambda expressions

Here is what i would like to achive: int id = 1; var db = new Project.Models.Context(); var query1 = db.Users.Where(t => t.id == id); //here is where the problem starts ...
deWord's user avatar
  • 46
1 vote
1 answer
4k views

Get a iqueryable items which do not exists on another list using lambda expression

I have an IQueryable(Of T) and a list of depended items List(of T). I am trying to achieve an IQueryable(Of T) which will exclude all the items in the List(of T). Dim returnQuery As IQueryable(Of ...
MJK's user avatar
  • 3,514
0 votes
1 answer
966 views

How to use .Where with lambda / IQueryable

Edit: Code works fine, it was an other bug. I had comment out the //department.IdAgency = reader.GetByte(2); line, in the created departmentList. When I removed the // then the IQueryable<string&...
MHP's user avatar
  • 81
5 votes
1 answer
2k views

AutoMapper Project().To<T> and reusable lambda expressions

I am having a problem getting a reuasable lambda expression working with the AutoMapper Project().To extension method. I am using AutoMapper 3.1.1. I want to be able to reuse a lambda expression by ...
user3430893's user avatar
4 votes
2 answers
435 views

IQueryable convertions

Why is conversion in line 'OK' possible, while not on line 'NOT OK'? var queryable = new int[]{1, 2, 3}.AsQueryable(); var x = (Expression<Func<IQueryable<int>>>)(() => (from c ...
user3284063's user avatar
0 votes
2 answers
175 views

Strange lambda Expression breaks down IIS

I do a query with an IQueryable<T> on an Entity.DbSet. When I insert this line of code: query = query.Where(x => x.VersionInt == query.Max(y => y.VersionInt)) The whole IIS breaks ...
user avatar
1 vote
0 answers
647 views

Dynamically add filter to Linq queryable which calls a DataContext method

I am having some trouble creating an expression to add to a queryable as a filter condition. I would like to replicate something the following: Starting with a simple queryable: IQueryable<...
user2592313's user avatar
0 votes
0 answers
803 views

Why is it that Entity Framework gives the error "Enumeration yielded no results" for typical many-to-many functionality?

Our ASP.NET C# web application is used in the following environment .NET Framework 4 ASP.NET Web Forms. IIS 7 Windows 2008 Visual Studio 2010 .NET IDE C# HTTPS ( SSL ) -Entity Framework 5 In ...
crazyTech's user avatar
  • 1,469
0 votes
1 answer
1k views

Where or (not and) with list of expressions c#

I got the following code public class Personnel { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int ...
user2331234's user avatar
1 vote
2 answers
1k views

Build LambdaExpression with custom parameter selection

Complete definition of my extension method goes first. static IQueryable<TResult> WithTicketNumbers<T, TResult>( this IQueryable<T> q, Expression<Func<T, Ticket>>...
AgentFire's user avatar
  • 9,710
2 votes
3 answers
9k views

Composing Expression<Func<T, bool>> predicates

I have a method that returns an Expression<Func<T, bool>> When I use this as a predicate in a where clause in EF this works fine, until I try to add more items to the predicate with ...
Oxymoron's user avatar
  • 1,392
0 votes
2 answers
749 views

c# translate SQL to lambda expression to get IQueryable

would be grate if someone could help me to translate this into lambda expression or something like. firstly introduction: are two tables/objects: OFFICE {officeID, NAME, another data} WORKER {ID,...
Edgar's user avatar
  • 1,120
1 vote
1 answer
52 views

How can I change my method to achive the following?

I have this method that is supposed to search collection of Employees by names. I pass the array of last names I want to find, and the method returns Employees with these names. Simple. public ...
Slava's user avatar
  • 6,590
0 votes
1 answer
408 views

SelectMany on an IQueryable ignores conditions?

I'm trying to use SelectMany to evaluate a first query with conditions, based on those results execute another query. I've been told that SelectMany should be able to do this. The problem I'm having ...
NullReference's user avatar
2 votes
0 answers
1k views

How to create filter expression dynamically in EF IQueryable?

Lets say we have interface: public interface ISystemCompany { Guid SystemCompanyId { get; set; } } We also have IQueryable<> of type, that implements ISystemCompany. We have specific ...
LukLed's user avatar
  • 31.8k
0 votes
2 answers
319 views

Convert/Embed one expression tree into another

EDIT: More detailed question. I am working on batched operations in nHibernate, specifically for In queries to overcome the 2100 parameter limit size in SQL Server. For this, I have created a class ...
Yogesh's user avatar
  • 14.6k