Date in expressions

Posts   
 
    
Andrius
User
Posts: 68
Joined: 04-Apr-2005
# Posted on: 22-Sep-2005 16:45:02   

Hello

I want to use in filter predicate experesion expression something like

ShipmentDate > OrderDate + OrderDuration

OrderDuration is an int field in database OrderDate and ShipmentDate are DateTime fields

Is it possible with LLBL (adapter scenario)?

Cadmium avatar
Cadmium
User
Posts: 153
Joined: 19-Sep-2003
# Posted on: 22-Sep-2005 18:46:17   

I don't know how to do this purely in code, but you can do this pretty easily if you set up a forumula field (assuming you are using Sql Server)

Create a new field (call it whatever you want, but I'll assume OrderDurationDate for this example) in your table and in the forumula field add something like:


(dateadd(day,[OrderDuration],[OrderDate ]))

Then you can do a basic predicate expression


PredicateFactory.CompareValue( MyEntityFieldIndex.ShipmentDate, ComparisonOperator.GreaterThan,  MyEntityFieldIndex.OrderDurationDate );

That's one way to do it! sunglasses

Andrius
User
Posts: 68
Joined: 04-Apr-2005
# Posted on: 23-Sep-2005 09:40:34   

Cadmium wrote:

I don't know how to do this purely in code, but you can do this pretty easily if you set up a forumula field (assuming you are using Sql Server)

Create a new field (call it whatever you want, but I'll assume OrderDurationDate for this example) in your table and in the forumula field add something like:


(dateadd(day,[OrderDuration],[OrderDate ]))

That's one way to do it! sunglasses

Yes, if you write a Typed View in DB, but in case of dynamic list I guess i 'll have to write my own expression for it

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39612
Joined: 17-Aug-2003
# Posted on: 23-Sep-2005 09:52:29   

ShipmentDate > OrderDate + OrderDuration can be written with llblgen pro code as well, because sqlserver is so friendly to perform the '+' on dates for you (it adds days to the date).

So ShipmentDate > OrderDate + OrderDuration can be broken down into: ShipmentDate > OrderExpression. You can do this with:


PredicateExpression filter = new PredicateExpression();
filter.Add(PredicateFactory.CompareExpression(MyEntityFieldIndex.ShipmentDate, ComparisonOperator.GreaterThan,
    new Expression(EntityFieldFactory.Create(MyEntityFieldIndex.OrderDate), ExOp.Add,
        EntityFieldFactory.Create(MyEntityFieldIndex.OrderDuration))));

Frans Bouma | Lead developer LLBLGen Pro