SQL and LLBLgen

Posts   
1  /  2
 
    
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 18-Mar-2009 11:01:01   

I don't think I said that.

What exactly do you want to do, let's start with that and go from there. And I understand that you want to cast something, but casting a string typed parameter to a string isn't really useful, so please give a real world example of what you want to do.

Frans Bouma | Lead developer LLBLGen Pro
Steria
User
Posts: 64
Joined: 26-Nov-2008
# Posted on: 18-Mar-2009 11:12:13   

When LLBLgen generate my query, I need to add on the where clause an explicit cast. They are some technical reason to add a cast on a varchar field.

So my generate sql should be :

SELECT * FROM ... WHERE CAST(:myFiled AS VARCHAR(10)) = "12345"

Regards,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 18-Mar-2009 12:17:46   

and myField is a field in an entity involved in the query? If not it won't work see a previous post of mine in this thread.

so first, fix the various issues with your code as I pointed out, make the .NET method cast accept an object typed parameter instead of a string typed parameter, then do for example:

new LinqMetaDataAdapter (adapter,new FunctionMapping());

from u in metadata.UsersEntity where FunctionMap.Cast(u.Code) == param select u.Code, u.userNamewhere

Frans Bouma | Lead developer LLBLGen Pro
Steria
User
Posts: 64
Joined: 26-Nov-2008
# Posted on: 18-Mar-2009 13:24:44   

Otis wrote:

and myField is a field in an entity involved in the query? If not it won't work see a previous post of mine in this thread.

so first, fix the various issues with your code as I pointed out, make the .NET method cast accept an object typed parameter instead of a string typed parameter, then do for example:

new LinqMetaDataAdapter (adapter,new FunctionMapping());

from u in metadata.UsersEntity where FunctionMap.Cast(u.Code) == param select u.Code, u.userNamewhere

I want to cast my parameter not the entity field. This is the reason why I want to have this one :

from u in metadata.UsersEntity where u.Code == FunctionMap.Cast(param) select u.Code, u.userNamewhere

Thanks for your support,

Regards,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 18-Mar-2009 13:57:13   

Steria wrote:

Otis wrote:

and myField is a field in an entity involved in the query? If not it won't work see a previous post of mine in this thread.

so first, fix the various issues with your code as I pointed out, make the .NET method cast accept an object typed parameter instead of a string typed parameter, then do for example:

new LinqMetaDataAdapter (adapter,new FunctionMapping());

from u in metadata.UsersEntity where FunctionMap.Cast(u.Code) == param select u.Code, u.userNamewhere

I want to cast my parameter not the entity field.

And why do you want to do that?

This is the reason why I want to have this one :

from u in metadata.UsersEntity where u.Code == FunctionMap.Cast(param) select u.Code, u.userNamewhere

No that's not the reason. You want to get: SELECT * FROM ... WHERE CAST(:myFiled AS VARCHAR(10)) = "12345"

you specify that :myField as a parameter in the query, but if you compare it with a constant, you can pre-cast it when you pass it to the query. i.e. 'param' is already a string in your linq query.

I'm sorry but I fail to understand what you really want to do, and I get the feeling you too don't fully understand what you want to accomplish, no offence.

(edit) What I want to know is WHY you want to cast something. And not because of some totally random query, I precisely want to know, in detail, what you want to do.

Btw, casts are automatically added to the query if you place Convert calls in the query. So if you do: from c in metaData.SomeEntity where Convert.ToString(c.SomeIntField)=="Blabla" select c; it will be casted.

WHat you don't seem to understand is that we need to know exactly WHAT you want to accomplish and WHY, so we can advice you to do this or that. The information you posted here so far is not sufficient.

Frans Bouma | Lead developer LLBLGen Pro
1  /  2