6
What is the difference in performance when using the basic query methods SqlQuery<TElement>
and ExecuteSqlCommand
of Entityframework in relation to directly using the ADO.NET?
If there is considerable difference in performance, this is due to the data processing performed in the application by Entityframework before accessing the database or the Entityframework also causes impacts on the database?
Using ADO.NET to perform a select
using (SqlConnection connection = new SqlConnection("connectionString"))
{
using (SqlCommand command = new SqlCommand("SELECT * FROM TABLE", connection))
{
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
///...
}
}
}
Using Entity Framework to perform a select with Sqlquery
context.Database.SqlQuery<Table>("SELECT * FROM TABLE");
Using ADO.NET to carry out an Insert statement
using (SqlConnection connection = new SqlConnection("connectionString"))
{
using (SqlCommand command = new SqlCommand("INSERT INTO TABLE VALUES ('foo', 'ba', GETDATE())", connection))
{
int records = command.ExecuteNonQuery();
}
}
Using Entityframework to perform an Insert statement with Executesqlcommand
context.Database.ExecuteSqlCommand("INSERT INTO TABLE VALUES ('foo', 'ba', GETDATE())");
Did the answer solve what you were looking to know? Do you think you can accept it now? If not, you need something else to be improved?
– Maniero