frenchie
frenchie

Reputation: 51937

c# ToList() and ToString()

I'm debugging a query with .SingleOrDefault() that's throwing an exception "subquery is returning more than one element."

SomeValue = (from...
             where ....
             select ...).SingleOrDefault()

I want to see for which value it's generating this bug so I changed it to this:

SomeValue = ((from...
              where ....
              select ...).ToList()).ToString()

The problem is that it's not returning a string of the list but it's returning "System.Collections.Generic.List1[System.String]"

How do I get the list to a string of elements separate by commas?

Thanks.

Upvotes: 1

Views: 1568

Answers (1)

Ethan Brown
Ethan Brown

Reputation: 27282

SomeValue = string.Join( ",", (from... where... select...) )

Upvotes: 9

Related Questions