IPredicate and datatypes in EntityView2 filters

Posts   
 
    
sbense
User
Posts: 55
Joined: 24-Jul-2007
# Posted on: 08-Aug-2007 16:49:54   

Is the Predicate system datatype sensitive when constructing filter expressions? I have run into an issue where the datatype supplied when constructing a EntityView2 object's filter seems to determine whether or not the filter is applied.

The code below shows the problem. Can someone confirm this is an issue or am I supposed to cast data to the exact type?

 Snippet
long Id = 1

Dim filterThisLong As IPredicate = (TblAccountTypeFields.AccountTypeId = Id)
Dim filterThisInt As IPredicate = (TblAccountTypeFields.AccountTypeId = CInt(Id))

'Create data collection
entityData = New EntityCollection(New MyTestEntityFactory())

'Retrieve data
adapter.FetchEntityCollection(entityData, Nothing)

'Filter data
viewData = entityData.DefaultView

'This does not work - no error, but the view has no data
viewData.Filter = filterThisLong 

'This works - view contains data
viewData.Filter = filterThisInt 
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Aug-2007 17:37:55   

Hi sbense,

The code below shows the problem. Can someone confirm this is an issue or am I supposed to cast data to the exact type?

You are supposed to provide the same type of the EntityField. If your code have a lot of casts like that you can add cast logic to your entities, overriding the FieldEntityProperties at yourEntity class.

David Elizondo | LLBLGen Support Team
sbense
User
Posts: 55
Joined: 24-Jul-2007
# Posted on: 08-Aug-2007 21:55:20   

David,

Thanks again for your help here. This solves the other issue I had with projections: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3861

While I appreciate the need to have datatypes the same, I think the framework classes should raise an error if they do not match and let the developer handle it. This is better than getting no data returned and no indication that there is a problem with the types. It took me ages to figure it out because there was just no hint at the problem.

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 08-Aug-2007 23:13:18   

I think the framework classes should raise an error if they do not match and let the developer handle it.

Yes. +1

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 09-Aug-2007 10:37:04   

In v2.5 it will convert the value to compare with to the type of the field and to the compare, to avoid these issues. If you compare a string with an int, it still won't work, but that's pretty obvious wink

Frans Bouma | Lead developer LLBLGen Pro
sbense
User
Posts: 55
Joined: 24-Jul-2007
# Posted on: 09-Aug-2007 14:11:19   

Otis wrote:

If you compare a string with an int, it still won't work, but that's pretty obvious wink

Yes agreed. It is less obvious when arguments to methods which then go on to construct IPredicate filters are differentiating between long and int types. As was the case with my sample instance.