0

Any time I use the code below it throws the error:

Method 'System.String Join(System.String, System.Collections.Generic.IEnumerable`1[System.String])' has no supported translation to SQL.

        var items = from t in fc.table
                    where t.id== objId
                    select new
                    {
                        t.id,
                        t.name,
                        string.Join(...)
                    };

I tried using the LINQ Aggregate method but got a similar error. Any suggestions on ways to get the string.Join functionality without the error?

Also, this code compiles fine. It's when I try to do something with items that it throws the error.

3
  • I don't know much about databases but could you use a stored procedure that does the same thing as Join? Commented Jun 28, 2010 at 17:13
  • Most likely. Don't confuse the join I am talking about here with a table join though. For my situation i'd like to figure out how to do it using LINQ. Commented Jun 28, 2010 at 17:24
  • It's not possible to do everything through LINQ - only a subset of .NET functions are supported. string.Join is on the list of unsupported methods. Commented Jun 28, 2010 at 17:26

1 Answer 1

2

Force the query to run on the client first, to extract the raw data, then join the strings in memory:

    var items = from a in (from t in fc.table
                           where t.id== objId
                           select new
                           {
                               t.id,
                               t.name,
                               t.a, t.b, t.c
                           }).AsEnumerable()
                select new
                {
                    a.id, 
                    a.name, 
                    string.Join(",", new[] { a.a, a.b. a.c })
                };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.