Problems with FieldValueRangePredicate

Posts   
 
    
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 05-Mar-2008 18:07:17   

ORM support 2.0.7.1213 SQL DQE 2.0.7.605 sql express db adapter

I have a string field and I want to compare the first character to a list of values. if i attempt to use a range predicate the strings are attempted to be converted to longs

Left(Myelds.StringField, 1) == new string[] {"A", "B", "C"};

public EntityField2 Left(IEntityField2 field, int numberOfCharacters)
{
      return new EntityField2(string.Empty, new DbFunctionCall("left", new object[] { field,  numberOfCharacters }));
}

output

where left([MyTable].[StringField], @numberOfCharacters) in (@a, @b, @c)

parameters:
int @numberOfCharacters = 1
long @a = A
long @b = B
long @c = C

however, if I use this predicate instead. it works correctly

Left(Myelds.StringField, 1) == "A" | Left(Myelds.StringField, 1) == "B" | Left(Myelds.StringField, 1) == "C"

any ideas?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 05-Mar-2008 22:54:54   

Hi Jason,

Seems to be related to the fact that the returntype of your function isn't known. So the EntityField2 type is used, however your new EntityField2 is by default an Int64 (I think). So you have to create the EntityField2 based on an existing stringType entity field:

So, try this:

// define the function
EntityField2 fieldWithLeft = CustomerFields.CompanyName.SetExpression(              
    new DbFunctionCall("LEFT", new object[] {CustomerFields.CompanyName, 1 }));

// define the filter
string[] values = new string[] { "A", "B", "C" };
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(fieldWithLeft == values);

Apply it to your code snippet and let us know if you need further help wink

David Elizondo | LLBLGen Support Team