2

I have the linq query below

var dd = (from dt in d
          select new
          {
              dt.id,
              dt.date,
              dt.customerid,
              dt.customer,
              dt.Description,
              dt.defect,
              dt.address,
              products = string.Join(",", dt.products)
          }).ToList();

string.Join didn't work, the error is

LINQ to Entities does not recognize the method 'System.String Format(System.String, System.Object, System.Object)'

I Googled a lot and couldn't find any other solution. What I want to do is, dt.Products is an array and I want to join it all together in a string. Is it possible in Linq to Entities?

0

1 Answer 1

6

You won't be able to do that within the query, but you can do it in memory by calling .AsEnumerable() first. Try this:

var dd = 
    (from dt in d
     select new
     {
         dt.id,
         dt.date,
         dt.customerid,
         dt.customer,
         dt.Description,
         dt.defect,
         dt.address,
         dt.products
     })
    .AsEnumerable()
    .Select(dt => new {
         dt.id,
         dt.date,
         dt.customerid,
         dt.customer,
         dt.Description,
         dt.defect,
         dt.address,
         products = string.Join(",", dt.products)
    }).ToList();

Note, however, if your data set is particularly large, this could cause a noticeable performance impact.

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.