C# DYNAMICALLY convert from DataTable to IEnumerable

Completed Posted 3 years ago Paid on delivery
Completed Paid on delivery

I am building an api

the database have 50 tables, table1,table2 .... to table50

the sql command saved into a DataTable dt, the dt columns is changing based on the sql command.

I want to convert the dt result to IEnumberable without building a class for each table, some tables have more than 200 columns. Building a class for each table is time consuming and not flexible.

I want to convert from dt to IEnumberable DYNAMICALLY, without the need of re-wrting everything again :

EXAMPLE:

for a single table I have the following: (table1):

public class table1values {

public string column1 {get; set;}

public string column2 {get; set;}

public string column3 {get; set;}

...

...

..

public string column200 {get; set;}

}

public IEnumerable< table1values > post(HttpRequestMessage value){

string sqlquery = "select * from table1"

DataTable dt = sqlQ(sqlquery) // send this command to execute the sql query and return dt

return [login to view URL](0,[login to view URL]).Select(index => new table1values {

column1 = [login to view URL][index][0].ToString(),

column2 = [login to view URL][index][1].ToString(),

....

....

column199 = [login to view URL][index][199].ToString(),

column200 = [login to view URL][index][200].ToString(),

}).toArray()

}

C# Programming .NET SQL ASP.NET JSON

Project ID: #29601926

About the project

2 proposals Remote project Active 3 years ago

Awarded to:

mahdimotlagh6137

Hi there. [login to view URL] has some features to cover your need. Although it is recommended to use entity classes for your tables but you can use these methods with a bit lower performance. I am a Dotnet developer with more tha More

$25 USD in 1 day
(1 Review)
0.5

2 freelancers are bidding on average $43 for this job

ndusan

Hey, I'm interested in your project. Please send me a message so that we can discuss more. Thank you. Dusan Nikolic

$60 USD in 7 days
(7 Reviews)
2.9