REPLACE db function in WHERE clause

Posts   
 
    
Posts: 9
Joined: 28-Feb-2009
# Posted on: 28-Feb-2009 10:54:22   

Hi, everyone...

I was wondering if anyone can help me convert the following query to LLBLGen format:

SELECT * FROM Locations WHERE REPLACE(ShortName, ' ','') = 'CzechRepublic'

The requirement is to compare a certain City/Country name (without spaces) with a DB City/Country name (with spaces). The above query removes the spaces in the names stored in DB.

The code is:

LocationsCollection cities = new LocationsCollection(); IPredicateExpression filterToUse = new PredicateExpression();

filterToUse.Add(LocationsFields.ShortName == cityName);

cities.GetMulti(filterToUse);

I need to change "LocationsFields.ShortName" but to what?

I tried Help > Generated code > Calling a database function. Didn't help.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Mar-2009 09:56:34   

You could use DBFunctionCalls. For example:

// the filter
EntityField fiedlWithReplace = 
    new EntityField("LocationShortNameSpaceStrip", new DbFunctionCall("REPLACE", new object[]{ LocationFields.ShortName, " ", ""}) );

IPredicateExpression filter = new PredicateExpression(fiedlWithReplace == "CzechRepublic");

// fetch
LocationCollection locations = new LocationCollection();
locations.GetMulti(filter);

HTH simple_smile

David Elizondo | LLBLGen Support Team
Posts: 9
Joined: 28-Feb-2009
# Posted on: 04-Mar-2009 12:08:47   

Thanks, that solved the problem...