Click here to Skip to main content
15,887,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one help here to find alternative option for .AsEnumerable() in asp.net core

What I have tried:

<pre> var StockList = (from dr in ds.Tables[0].AsEnumerable()
                                 select new
                                 {
                                     BrandID = dr.Field<int>("BrandID"),
                                     BrandName = dr.Field<string>("BrandName")
                                 }
                                 ).ToList();
Posted
Updated 22-Apr-18 0:22am

1 solution

A simple alternative would be a for loop. For example consider the following
C#
System.Collections.Generic.List<object> StockList = new System.Collections.Generic.List<object>();
for (int counter = 0; counter < ds.Tables[0].Rows.Count; counter++) {
   StockList.Add(new {
      BrandID = ds.Tables[0].Rows[counter]["BrandID"],
      BrandName = ds.Tables[0].Rows[counter]["BrandName"]
   });
}
 
Share this answer
 
v2
Comments
Wendelius 22-Apr-18 6:41am    
Fixed the typo in table name

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900