Questo è come attualmente sto selezionando i dati dal database:Come selezionare i dati nell'elenco <T> anziché DataTable?
public DataTable GetData()
{
DataTable table = new DataTable("Table");
using (SqlConnection connection = new SqlConnection("Connection string"))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "query string";
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(table);
}
return table;
}
Ma tornare DataTable e voglio selezionare Lista invece di DataTable. Come questo:
public List<MyClass> GetData()
{
DataTable table = new DataTable("Table");
using (SqlConnection connection = new SqlConnection("Connection string"))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "query string";
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(table);
}
...
return [List of MyClass];
}
Come posso fare questo?
Grazie!
Ti sicuramente voglia di utilizzare le chiamate ADO.NET di basso livello piuttosto che LINQ to SQL o Entity Framework? –
Non ne sono sicuro. Ma penso che ADO.NET di basso livello sarà più veloce. – WaterDance
Sì, ADO.NET sarà più veloce, ma questo guadagno di velocità fa la differenza per il tuo ambiente? –