concatenation of strings and integers in select

Posts   
 
    
shuep
User
Posts: 4
Joined: 22-May-2009
# Posted on: 22-May-2009 17:40:58   

One of the values in a select statement I have is created by concatenating a few columns from the database together.

Something like:


var q = from r in md.MyTable
            select new { mycode = r.Prefix + (r.No ?? 0) + r.Suffix1 + r.Suffix2 };

everything but r.No is a normal string, r.No is a nullable int.

If I do nothing, it will try and convert the r.Prefix value to an int, which of course fails. If I try to do anything like:


var q = from r in md.MyTable
            select new { mycode = r.Prefix + (r.No ?? 0).ToString() + r.Suffix1 + r.Suffix2 };

It will give me an error: "The parameter at position 1 is of an unsupported type: Call"

I assume it is trying to do the concatenation at the DB level instead of at the application level?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2009 20:39:15   

Please follow these instructions to post so we can figure this out.

Show us the complete stack trace and the generated sql for the second query. Here is how enable tracing.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 23-May-2009 10:37:34   

The '+' operator is indeed executed at the DB level. If you want to have it executed on the app level, create a static method, pass the fields (not the entity) to the method and do the concatenation there.

Frans Bouma | Lead developer LLBLGen Pro
shuep
User
Posts: 4
Joined: 22-May-2009
# Posted on: 26-May-2009 14:53:01   

Otis wrote:

The '+' operator is indeed executed at the DB level. If you want to have it executed on the app level, create a static method, pass the fields (not the entity) to the method and do the concatenation there.

Oddly, it will not take String.Join(), (Method call to 'Join' doesn't have a known mapped database function or other known handler). I had thought that String.Join() was static. I ended up creating a static wrapper function which worked.