Posts

Showing posts with the label .Net Core

call stored procedure with parameter in entity framework core 6

  To call a stored procedure with parameters in Entity Framework Core 6, you can use the FromSqlRaw or FromSqlInterpolated methods, passing the parameters as arguments. Here's an example of how you can call a stored procedure with parameters: Assuming you have a stored procedure named GetUsersByAge that takes an @age parameter and retrieves a list of users based on their age, and you have a User class representing your users: csharp Copy code public class User { public int Id { get ; set ; } public string Name { get ; set ; } // other properties } Here's how you can call the GetUsersByAge stored procedure with a parameter in Entity Framework Core 6: csharp Copy code public List<User> GetUsersByAgeFromStoredProcedure ( int age )   {  using ( var context = new YourDbContext()) { var users = context.Users .FromSqlRaw( "EXEC GetUsersByAge @age" , new SqlParameter( "@age" , age)) .ToList()...

.NET Core 6.0 Entity Framework Core DB First

Image
  Entity Framework Core 6 with Database First in .NET 6 This article will explain how to connect your .NET 6 application to an existing database using Entity Framework Core. Alongside the theory will be given a practical example where we create a new Console Application using .NET 6, this console application then will be connected to a pre-existing sample of the NorthWind DB with Entity Framework Core and the Database First approach. If we compare Database First approach in Entity Framework Core using .NET 6 to previous .NET framework versions we can notice that some important changes were made. Before we had our database based on the .EDMX file, and had to update this .EDMX file every time we had any updates on the database. Now with the scaffold command, we create the same entities as if we created the database using the code first approach. What is Entity Framework Core? Entity Framework Core is Microsoft's most powerful ORM - Object Relational Mapper, that helps ...