Date filter error, when comparing two datetime field

Posts   
 
    
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 30-Mar-2005 19:56:42   

Hi Otis,

I have a typedview, that contains two datetime field (on SQL Server), date1 and date2.

I want to filter all the records, where the date1>=date2.

I tried this:

dim myBucket as new RelationPredicateBucket dim myQuery as MyTypedView

MyBucket.PredicateExpression.add(PredicateFactory.CompareValue( _ MyTypedViewFiledIndex.date1, ComparisonOperator.GreaterThan, _ MyTypedViewFiledIndex.date2))

MyAdapter.FetchTypedView(MyQuery.GetFieldsInfo, MyQuery, MyBucket, false)

When I execute this code, get the following exception:

"Invalid cast from enum to DateTime" confused

Is it a bug, or I missed something?

Thanks in advance

Gabor

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 30-Mar-2005 21:07:38   

I found the Frans's answer to this item (use the FieldCompareExpressionPredicate instead of PredicateFactory.CompareValue):

IPredicateExpression filter = new PredicateExpression(); filter.Add(new FieldCompareExpressionPredicate( EntityFieldFactory.Create(OrderFieldIndex.OrderDate), ComparisonOperator.LesserThan, new Expression(EntityFieldFactory.Create(OrderFieldIndex.OrderDate)) ));

but if I tried them, get the error

"Specified cast is not valid", when on try to return the datetime.minvalue.

Thanks in advance

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Mar-2005 21:53:31   

Gabor wrote:

I found the Frans's answer to this item (use the FieldCompareExpressionPredicate instead of PredicateFactory.CompareValue):

IPredicateExpression filter = new PredicateExpression(); filter.Add(new FieldCompareExpressionPredicate( EntityFieldFactory.Create(OrderFieldIndex.OrderDate), ComparisonOperator.LesserThan, new Expression(EntityFieldFactory.Create(OrderFieldIndex.OrderDate)) ));

but if I tried them, get the error

"Specified cast is not valid", when on try to return the datetime.minvalue.

Thanks in advance Gabor

You indeed have to use an Expression. Though I'm not quite sure where you try to return the minvalue, as the filter you've specified just filters, so I'm a bit confused where the minvalue is used... (I've deleted your duplicate post)

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 31-Mar-2005 11:54:18   

Thanks Frans,

I don't want to return the minvalue, but when I traced, saw, that the ORMHelperClass try to return a dateTime.minvalue, that invoked an invalid cast exception.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 31-Mar-2005 12:02:20   

Gabor wrote:

Thanks Frans,

I don't want to return the minvalue, but when I traced, saw, that the ORMHelperClass try to return a dateTime.minvalue, that invoked an invalid cast exception.

Thanks Gabor

When a field is NULL in the database, the default value is returned for that value. In this case DateTime.MinValue is returned as default value in that case.

When exactly do you get teh cast error? Could you paste that small piece of code here and also the stack trace? That would be a great help, thanks simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 31-Mar-2005 12:18:24   

Thanks Frans,

I created a view that contains the required comparison.

My question is, what is the overhead using the expression predicate over the using predifined view?

I would prefer using predicate expression, because of the cleaner code, and better to store all business logic code in one place.

My appl. is in another place, so will post the code and the trace later.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-Apr-2005 11:48:35   

Gabor wrote:

Thanks Frans,

I created a view that contains the required comparison.

My question is, what is the overhead using the expression predicate over the using predifined view?

THe overhead will be that the query has to be created but that's very fast. The query execution time is the same.

Frans Bouma | Lead developer LLBLGen Pro