Conversion between IEnumerable EnumerableRowCollection

199 Views Asked by At

I have the following code:

var aaData = myapi.GetData().AsEnumerable().Select(x => new {
                Id = x["myID"],
                Desc = x["myDesc"]                   
            });

Trying to do the following

aaData = aaData.OrderBy((string.Join(",", request.Order
.Select(x => request.Columns[x.Column].Data + " " + x.Dir))));

Getting error:

CS0266 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<>' to 'System.Data.EnumerableRowCollection<>'. An explicit conversion exists (are you missing a cast?)

How to fix this?

GetData returns a DataTable

Request is an object having a property:

public OrderCol[] Order { get; set; }

OrderCol is

public class OrderCol {
            public int Column { get; set; }
            public string Dir { get; set; }
        }

Thanks for your assistance.

The above code works for the case when I get a List<> back instead of DataTable. The error states that a Cast is needed and it seems to be how DataTable.AsEnumerable is set up as a EnumerableRowCollection

Can use a mock datatable to mimic the above

DataTable dt = new DataTable();
 dt.clear();
 dt.Columns.Add("myID");
 dt.Columns.Add("myDesc");
1

There are 1 best solutions below

0
On

all i needed was to convert to a list and things worked fine