The latest version of Microsoft Asp.Net Core and Entity Framework Core is a hot topic in the market. Today, I am talking about how to call stored procedure from Entity Framework Core.
Here I am not teaching you. How to create stored procedure. Hope you already know it.
The support for stored procedure in Entity Framework Core is similar to the earlier versions of Entity Framework.
Let's see example
Before calling stored procedure using Entity Framework Core. You require to include package "Microsoft.EntityFrameworkCore.SqlServer" to support calling stored procedure on the project.json file.
AsNoTracking
Disabling change tracking is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each entity instance.
You should not disable change tracking if you want to manipulate entity instances and persist those changes to the database using Microsoft.EntityFrameworkCore.DbContext.SaveChanges.
Hope you like this post and keep reading!!
Here I am not teaching you. How to create stored procedure. Hope you already know it.
The support for stored procedure in Entity Framework Core is similar to the earlier versions of Entity Framework.
Let's see example
_context.Set<Products>().FromSql("GetAllProducts @CategoryId = {0}", categoryId).AsNoTracking().ToList()We are calling "GetAllProducts" stored procedure passing categoryId.
Before calling stored procedure using Entity Framework Core. You require to include package "Microsoft.EntityFrameworkCore.SqlServer" to support calling stored procedure on the project.json file.
AsNoTracking
Disabling change tracking is useful for read-only scenarios because it avoids the overhead of setting up change tracking for each entity instance.
You should not disable change tracking if you want to manipulate entity instances and persist those changes to the database using Microsoft.EntityFrameworkCore.DbContext.SaveChanges.
Hope you like this post and keep reading!!
0 comments:
Post a Comment