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.