1
votes

this is my code

public IEnumerable<TestUser> Getdata()
{
        //return new string[] { "value1", "value2" };
    TestUserBl tstusr = new TestUserBl();
    DataTable dt = new DataTable();
    dt = tstusr.TestUserSel();
    return dt.AsEnumerable();
}

getting error

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

1
What do TestUserSel() method do? - Alexander

1 Answers

2
votes

Actually DataTable.AsEnumerable() gives you EnumerableRowCollection as the error message stated, if you need to get the specific object collection you have to get that object like the following:

public IEnumerable<TestUser> Getdata()
{
    // Code here
    return dt.AsEnumerable().Select(x => new TestUser{
                              someId = x.Field<string>("id"),
                             // like wise initialize properties here
                             });
}