You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Entity Framework, there is a method to execute a query against the database and return a specified object type. Entity Framework Core does not have this and the only alternative is 4 times the amount of code. Example below.
Database.SqlQuery (Entity Framework 6.0)
This is the SqlQuery method found in Entity Framework 6.0
varintegerList= db.Database.SqlQuery<int>("SELECT [MyIntegerColumn] FROM [MyTable]").ToList();foreach(int id in integerList){// do something with each in the list or just return the list}
SqlCommand (Entity Framework Core 2.0)
This is the DbDataReader method found in Entity Framework Core 2.0
using(varcommand= context.Database.GetDbConnection().CreateCommand()){
command.CommandText ="SELECT [MyIntegerColumn] FROM [MyTable]";DbDataReaderreader=await command.ExecuteReaderAsync();if(reader.HasRows){while(await reader.ReadAsync()){// do something with each in the list or just return the list}}}
Honestly, quadrupling the amount of code required to perform the same action and expecting the same result is not "more efficient" in my opinion. I have literally dozens of "quick calls" as I call them in my code that will now require me to convert a single line of code over to 4 (or more).
The text was updated successfully, but these errors were encountered:
Meanwhile you can try netcore-ef-util and a code like follow
using SearchAThing.EFUtil;using System.Linq;
...
var integerList = db.ExecSQL<int>("SELECT [MyIntegerColumn] FROM [MyTable]");foreach(int id in integerList){// do something with each in the list or just return the list}
In Entity Framework, there is a method to execute a query against the database and return a specified object type. Entity Framework Core does not have this and the only alternative is 4 times the amount of code. Example below.
Database.SqlQuery (Entity Framework 6.0)
This is the SqlQuery method found in Entity Framework 6.0
SqlCommand (Entity Framework Core 2.0)
This is the DbDataReader method found in Entity Framework Core 2.0
Honestly, quadrupling the amount of code required to perform the same action and expecting the same result is not "more efficient" in my opinion. I have literally dozens of "quick calls" as I call them in my code that will now require me to convert a single line of code over to 4 (or more).
The text was updated successfully, but these errors were encountered: