Need some help with FieldBetweenPredicate

Posts   
 
    
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 28-Jan-2009 05:53:29   

In the code below I would like to check to see if today is between the start and range stored in the db. However it looks like there are some limitations to compare Entity Fields with local variables? How would I do this? I am using self service.

I looked at the FieldCompareExpression as well but it is also field to field.

PreSeasonScheduleCollection shipWindows = new PreSeasonScheduleCollection(); IPredicateExpression dateFilter = new PredicateExpression(); dateFilter.Add(new FieldBetweenPredicate(Convert.ToDateTime(ThisDate), PreSeasonScheduleFields.ShippingWindowStart, PreSeasonScheduleFields.ShippingWindowEnd);

SQL would be some like

select * from PreseasonSchedule where myDate >= PreseasonStartDate And myDate <= PreSeasonEndDate

Thanks in advance for your help,

Todd

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jan-2009 06:49:20   

Indeed, FieldBetweenPredicate is intended to compara a Field and a range of two Values. So you will have to elaborate the predicate with two normal compare predicates.

David Elizondo | LLBLGen Support Team
rtbike
User
Posts: 23
Joined: 23-Jan-2009
# Posted on: 28-Jan-2009 20:57:49   

could you point me to an example of a normal compare predicate?

can I just say:

IPredicateExpression filterSeries = new PredicateExpression(); filterSeries.Add(SeasonFields.BookingDeadline >= myDate) filterSeries.AddWithAnd(SeasonFields.BookingDeadline <= myDate)

if the above works is there an advantage to you the special pedicates over this?

Also what is the difference between Ipredicate.Expression and Predicate.Expression?

Sucks to be new simple_smile

Todd

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Jan-2009 07:37:01   

rtbike wrote:

could you point me to an example of a normal compare predicate?

can I just say:

IPredicateExpression filterSeries = new PredicateExpression(); filterSeries.Add(SeasonFields.BookingDeadline >= myDate) filterSeries.AddWithAnd(SeasonFields.BookingDeadline <= myDate)

That's it wink

rtbike wrote:

if the above works is there an advantage to you the special pedicates over this?

There're some predicates that are shortcuts, for example:

To achieve this SQL:

Field IN (1, 2, 5, 10)
Field IN ("Foo", "Bar", "Blah")

You can do this:

int[] values = new int[3] {1, 2, 5};
filter.Add(new FieldCompareRangePredicate(OrderFields.EmployeeId, values));

// which is equal to:
filter.Add(OrderFields.EmployeeId == values);

Instead of writing 3 normal predicates.

In brief, you can do a lot of thing with predicates, and expression. I recommend to you read this topics: - The predicate system - Advance filter usage - Expressions and aggregates

Those links are a good start to build whatever you want on LLBLGenPro (well, at least a bunch of things simple_smile then you could keep reading)

David Elizondo | LLBLGen Support Team