Hello,
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;
begin
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)
else
lCondition := null;
lQuery := Linq.From(FDatabase.Context['Work'])
.Where(lCondition)
.Select;
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?
Thanks
Linq where condition
Re: Linq where condition
Hello,
You cannot use Null as the lCondition condition. Null can be used as the condition operand, i.e.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:
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.
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;