Database function in a query

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 16-Feb-2010 16:01:37   

I need to express following queru.

select * from table1 where value=function(parameter1,'ssss')

The parameter1 value is passed and the sss value is always the same.

I read in the doc I have to create an expresion, but I dont know where to start.

Thanks in advance.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 16-Feb-2010 22:02:19   

You should be able to do something like


IPredicate functionFilter = new EntityField("OrderMonth", new DbFunctionCall("dbo.function({0},{1})", new object[] {parameter1,"ssss"})

and use this as the filter on a query to retrieve a dynamic or typed list.

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 17-Feb-2010 10:05:02   

Hmm I've tried your code

IPredicate functionFilter = new EntityField("OrderMonth",new DbFunctionCall("dbo.function({0},{1})",new object[] {"aaa", "ssss"});

but intelisense says:

Cannot convert source type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField' to target type 'SD.LLBLGen.Pro.ORMSupportClasses.IPredicate'

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Feb-2010 10:56:21   
select * from table1 where function(parameter1,'ssss')=value

I guess he meant the following:

var field = new EntityField("OrderMonth",new DbFunctionCall("dbo.function({0},{1})",new object[] {"aaa", "ssss"});

var filter = new PredicateExpression(field == value);
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 17-Feb-2010 13:19:42   

Yes, this worked perfect! Thank you both guys!