Linq where condition

Discussion of open issues, suggestions and bugs regarding EntityDAC
Post Reply
Posts: 12
Joined: Wed 25 Jan 2017 14:44

Linq where condition

Post by rbeeston » Wed 01 Mar 2017 11:45

I'd like a linq where condition which varies depending on user input.

e.g. something like

lWorks : IEntityEnumerable<TWork>;
lWork : TWork;
lCondition : TExpression;
lQuery : ILinqQueryable;
if dtmStart.Checked and dtmFinish.Checked then
lCondition := (FDatabase.Context['Work']['JobDate'] > dtmStart.DateTime) and
(FDatabase.Context['Work']['JobDate'] < dtmFinish.DateTime)
else if dtmStart.Checked then
lCondition := (FDatabase.Context['Work']['JobDate'] > dtmStart.DateTime)
else if dtmFinish.Checked then
lCondition := (FDatabase.Context['Work']['JobDate'] < dtmFinish.DateTime)
lCondition := null;

lQuery := Linq.From(FDatabase.Context['Work'])

lWorks := FDatabase.Load<TWork>(lQuery);
for lWork in lWorks do

The clauses where dates are specified are working ok, but the null condition doesn't work. How can i create such?


Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Linq where condition

Post by AlexP » Mon 24 Apr 2017 09:49


You cannot use Null as the lCondition condition. Null can be used as the condition operand, i.e.

Code: Select all

FDatabase.Context['Work']['JobDate'] = Null. 
In this case, a correct query will be created.

If you want to use your code and not to set conditions (select all records) you should specify the condition as follows:

Code: Select all

lCondition := 1 = 1; 

Post Reply