Linq where condition
Posted: Wed 01 Mar 2017 11:45
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
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