1

How to convert Object to List.

Can anybody tell me how to fix this issue.

This is the Error I am getting.

user957178
  • 631
  • 4
  • 15
  • 27
  • As a note the line `query2.Where(x => x.ba_Object_id != baObjectID);` doesn't look to do anything. `Where` doesn't change the original object, it just returns a new one which you are not using. – Chris Dec 07 '11 at 17:32
  • http://stackoverflow.com/questions/480399/convert-listof-object-to-listof-string – huMpty duMpty Dec 07 '11 at 17:53

1 Answers1

6

The problem is that your list is a List<string>, but your query returns a collection of baObject. You need to either use ToString() on this, or change your query to return a specific member.

The first option would look like:

descList.AddRange(query2.Select(ba => ba.ToString()).ToList());

The second (more likely option) could be as simple as:

descList.AddRange(query2.Select(ba => ba.Name).ToList());

(This is assuming baObject.Name is the property you want to list.)

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373