views:

38

answers:

2

I have two long type columns that I want to concat during sql query. Using Linq to Entities making it impossible, because it only supports String.Concat(string, string).

I'd like to know how can I implement this function myself and add it to the L2E framework.

A: 

Can't you convert them to strings first, by doing String.Concat(long1.ToString(), long2.ToString())? Or is this not understood by the framework either?

Take a look at this question, which talks about some workarounds for this problem. Maybe you can adapt something to work here as well?

lc
ToString() is not supported by L2E. Look here: http://msdn.microsoft.com/en-us/library/bb738681.aspx
Eran Betzalel
@Eran Betzalel I see. After a bit of digging, this looks like a common problem - there are a few related questions on SO. Not sure if it's helpful, but would be at least worth a look.
lc
The solution on these questions is not for me (my current situation suggests that using ToList will simply get all the table's content).
Eran Betzalel
A: 

What's the point in doing the concat in SQL ? You can do it in a projection when you receive the data :

var query = from foo in db.Foo
            select new { foo.X, foo.Y };

var result = from foo in query.AsEnumerable()
             select foo.X.ToString() + foo.Y.ToString();

I'd like to know how can I implement this function myself and add it to the L2E framework.

I don't think that's possible, unless you want to implement your own EF provider...

Thomas Levesque
I was thinking about extending it.
Eran Betzalel
I doubt that is possible... If you want to know more about how the provider is implemented, have a look at it using Reflector. I suggest you buy a stock of aspirin beforehand ;)
Thomas Levesque