How to convert Object to List.
Can anybody tell me how to fix this issue.
This is the Error I am getting.
How to convert Object to List.
Can anybody tell me how to fix this issue.
This is the Error I am getting.
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.)