![]() And true to their word, there was a lot of work done on updates that EF Core sends to the database. At that time, the team committed to focusing on improving the performance of other workflows in EF Core 7. Faster and Faster!īack in 2021, one of the biggest stories for EF Core 6 was the dramatic performance improvement for non-tracking queries. ![]() So, I may wait until EF Core 8 to use the new nickname. I still remember that first version of EF Core, just after EF6, which had a working name of EF7 until it became EF Core. You'll find this article filled with some of the features that will be most impactful to the bulk of dev teams as well as a few that I personally found interesting.Īlthough I will always refer to this version as EF Core 7, keep in mind that much of the documentation and other resources will use EF7 as its nickname. ![]() Not only does it mean writing about them, but I also get to test them all out, which is quite a lot of fun, thanks to the fact that I don't have to do so with the goal of releasing production code. I've been overwhelmed in trying to choose which of its features to share with you here. So you can continue using it on a supported version of. NET 6, which is the long-term support version of. Although EF Core 7 is being released alongside. That has a lot do with the fact that the team has made a big investment in creating a stable base to build on. The code here doesn’t conflict with Entity Framework database context and it is safe to use for data reading as it doesn’t leave any data readers open.Lately, it seems that each iteration of EF Core brings fabulous new features and improvements. This post focused on a shortcut methods like ExecuteSqlCommand() and ExecuteSqlCommandAsync() and also took raw ADO.NET to focus as it is sometimes the work horse we actually need. There are multiple ways to execute raw SQL commands using Entity Framework Core. You can also derive your own common view for your DataTables using my code as a starting point. If you write views or procedures for reporting where field names are replaced by human readable names then you can use my common DataTable view to display DataTables. For reporting DataTable is ideal – we can change the structure of data returned by SQL command and everything still works.Ĭommon view for DataTable. We are still running commands in database context but what we are doing is not monitored by Entity Framework core. Using this code we can also run custom SQL commands and not only stored procedures. CreateParameter() įorDateParam.ParameterName = DbType.Date CreateCommand())Ĭommand.CommandText = "sp_AverageTemperaturesReport" public async Task GetAverageTemperatures( DateTime forDate) What has best worked for me is loading data to DataTable like shown here. It’s sometimes tempting to return data reader to keep things minimal but be aware – you are taking a great responsibility! Before running any other command on same connection the data reader must be closed or you end up with exception. Good example is reporting data we are showing as a table on web page. Sometimes we need to get data back from custom raw SQL. It just executes stored procedure and this is it. CreateCommand())Ĭommand.CommandText = "sp_BalanceUpdate" Ĭommand.CommandType = CommandType.StoredProcedure public async Task UpdateBalanceForCustomers() Here’s the code from first sample of this post but it is implemented using raw database objects. We can use ADO.NET data objects to get complete control and go around all wisdom coming with Entity Framework Core. These methods are fine but how they are executed is decided by Entity Framework Core. ExecuteSqlCommandAsync( "EXEC sp_Customer BalanceUpdate customerId) public async Task UpdateBalanceForCustomer( int customerId)Īwait Database. We can also use parameters with these methods like shown here. ExecuteSqlCommandAsync( "EXEC sp_BalanceUpdate") public async Task UpdateBalanceForCustomers()Īwait Database. Here’s the example of running stored procedure to update balance for all customers. In this post I will demonstrate how to run raw SQL commands in Entity Framework Commands and how to read data from database without DbSet and query types.Įntity Framework Core has ExecuteSqlCommand() and ExecuteSqlCommandAsync() methods to run custom SQL queries and commands. There have always been those special cases when raw SQL commands are needed. I have never seen a real-life project where object-relational mapper generates 100% of needed SQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |