Dirk68 (3) [Avatar] Offline
#1
Hello everybody!

The following linq-syntax works:

Dim qry = From tbl1 In DataContext1.tbl1 _
SELECT strCalculated = String.Concat("ABC", tbl1.field1.ToString)
But the following nested expression does NOT work:

Dim qry = From tbl1 In DataContext1.tbl1 _
SELECT strCalculated = String.Concat("DEF", String.Concat("ABC", tbl1.field1.ToString) )

Error-Message: "Could not translate Expression concat(VB$Ii$.strCalculated, "ABC") into SQL and could not treat it as a local expression."

Does anybody know why?
Dirk68 (3) [Avatar] Offline
#2
Re: LINQ: nested expressions not allowed?
Sorry! This behaviour only occurs if you use an extended method of the string-class instead of the ToString-method. It works once, but not nested. Why?
jwooley (123) [Avatar] Offline
#3
Re: LINQ: nested expressions not allowed?
The LINQ to SQL provider tries it's best to translate the LINQ expression tree into the equivalent TSQL statement. As we show in chapter 6, it is not able to handle all cases. It appears that you have found one of the cases where it doesn't recurse far enough into the expression tree. In these cases, you may need to do the concatenation on the client rather than the server by forcing a .ToList before the select statement.

Jim
Dirk68 (3) [Avatar] Offline
#4
Re: LINQ: nested expressions not allowed?
Hello Jim,

This helps me because I searched for MY error all the time and now I know that I just have to find a work-around.

I thank you very very much for your answer.

Cheers
Dirk Lynen from Germany