LINQKit is a free set of LINQ extensions, aimed primarily at LINQ to SQL. With LINQKit, developers can: Plug expressions into EntitySets, use expression variables in subqueries, combine expressions (have one expression call another), dynamically build query predicates, and leverage AsExpandable to add new extensions.
Questions tagged [linqkit]
142 questions
5
votes
1 answer
Error casting FieldExpression to LambdaExpression using Linq to SQL
I'm getting the error Unable to cast object of type 'System.Linq.Expressions.FieldExpression' to type 'System.Linq.Expressions.LambdaExpression' when running the below code.
The intent of this code is to allow me to filter records (Entity Framework…

JohnLBevan
- 22,735
- 13
- 96
- 178
5
votes
2 answers
Trying to use parent property as parameter in child collection expression; LinqKit throws "Unable to cast MethodCallExpressionN to LambdaExpression"
I'm trying to dynamically construct an expression similar to the one below, where I can use the same comparison function, but where the values being compared can be passed in, since the value is passed from a property 'higher-up' in the query.
var…

Ben Jenkinson
- 1,806
- 1
- 16
- 31
5
votes
3 answers
Building a custom predicate to act as a filter using a foreach loop
I need to filter a list of documents by passing them to a custom filter that I'm struggling to build dynamically using a foreach loop :
var mainPredicate = PredicateBuilder.True();
// mainPredicate is combined to other filters…
user2324540
4
votes
1 answer
Includes doesn't work with LinqKit AsExpandable
I'm trying to use LinqKit AsExpandable in my EfCore2.0 project and I am running into this problem where the Includes doesn't work.
In attempting to debug this I have downloaded the LinqKit source from github and have replaced the Nuget references in…

jag
- 517
- 6
- 16
4
votes
1 answer
Adding to Lambda Expression and work with Entity Framework
If I want retrieve more columns with an already existing lambda tree expression
like below, how would I do that? This works with Entity Frameworks and want it to still work.
Expression> columns= (d) => new…

Mike Flynn
- 22,342
- 54
- 182
- 341
4
votes
1 answer
"Include" extension method does not work with LinqKit
I have 2 classes:
public class Employee
{
public int Id {get;set;}
public string Name {get;set;}
}
public class Remuneration
{
public int Id {get;set;}
public Employee Employee {get;set;}
public int Amount {get;set;}
}
The…

Satyajit
- 1,971
- 5
- 28
- 51
4
votes
2 answers
Creating a dynamic Linq select clause from Expressions
Let's say I have defined the following variables:
IQueryable myQueryable;
Dictionary>> extraFields;
// the dictionary is keyed by a field name
Now, I want to tack on some dynamic fields to the…

Shaul Behr
- 36,951
- 69
- 249
- 387
4
votes
1 answer
Is there a LINQKit version for EF 5.0 ? Otherwise what other could I use for EF 5.0?
Ey there, I just see the latest LINQKit version depends of EF 6.0.2, I need to install on EF 5.0, is there an older LINQKit version for EF 5.0 compatibility ? Or something else to replace it (.Expand() functionality) ?

Jrr
- 167
- 1
- 4
- 14
4
votes
1 answer
Why am I getting an InvalidCastException when using an expression from a static field?
I'm just starting to use LinqKit with EntityFramework 6.0.2 and I have the following question...
Why does this:
public static readonly Expression> ConvertToString = e =>
e == MyEnum.One
? "one"
…

kmp
- 10,535
- 11
- 75
- 125
4
votes
2 answers
Call Expression within a LINQ to Entities Select with LINQkit
Here's what I want to do :
class MyDbContext : DbContext
{
private static Expression> myExpression1 = x => /* something complicated ... */;
private static Expression> myExpression2 = x => /* something else…

billy
- 1,165
- 9
- 23
3
votes
1 answer
PredicateBuilder And or Or
In all the examples I've seen for predicate builder it shows a starting expression with PredicateBuilder.True if you are building an "and" expression criteria and PredicateBuilder.False if you are building an "or" expression criteria.
My questions…

Simon Lomax
- 8,714
- 8
- 42
- 75
3
votes
0 answers
The LINQ expression cannot be translated when using null check
I'm using projection in EF Core with Linqkit to reuse expressions with Invoke(). I want to apply filters to projected models:
public class TransportModel
{
public Guid Id { get; set; }
public InmateModel Inmate { get; set;…

Snaketec
- 471
- 2
- 14
3
votes
1 answer
LinqKit nested invoke "LINQ to Entities does not recognize the method 'Invoke'"
I do not fully understand why nested invokes in select do not work within LinqKit and was wondering if someone would be able to help me understand.
My problem:
First let me line out what works.
So lets say we have three db objects:
public class…

GrizzlyEnglish
- 99
- 1
- 7
3
votes
1 answer
Load related data with EF Core 3.1
I'm not sure if I'm doing something wrong or if this is a bug in EF Core 3.1 but the following works with EF 6.x and is part of a Generic Repository which I'm converting to EF Core 3.1:
IQueryable query = this.Context.Set();
…

Thierry
- 6,142
- 13
- 66
- 117
3
votes
0 answers
Simple alternative to PredicateBuilder for Linq to objects to work with Func instead of Expression
Everybody loves the LinqKit library by Joe Albahari, and its PredicateBuilder.
However, it has a drawback due to the usage of Expression<> :
Expression needs to be compiled, which takes a lot of time when you use it oftenly.
In some of my…

AFract
- 8,868
- 6
- 48
- 70