1599214200
Stored procedures are an integral part of any MS SQL database. They are perfect to wrap complicated SQL into a database object, that we can reuse. How to execute a stored procedure that returns data in Entity Framework Core 5? In my last post: Execute a stored procedure with Entity Framework Core 5 I showed how to run a stored procedure, but selecting the data it’s a different kind of story. Let’s have a look.
First of all, we need to add a stored procedure. The best way to do so is to add a database migration with an appropriate SQL. Let’s start by adding a migration with EF Core global tool command:
dotnet ef migrations add spGetGuestsForDate
This will generate a migration, that we can put our SQL into. Let’s see how it may look:
public partial class spGetGuestsForDate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var sql = @"
IF OBJECT_ID('GetGuestsForDate', 'P') IS NOT NULL
DROP PROC GetGuestsForDate
GO
CREATE PROCEDURE [dbo].[GetGuestsForDate]
@StartDate varchar(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT p.Forename, p.Surname, p.TelNo, r.[From], r.[To], ro.Number As RoomNumber
FROM Profiles p
JOIN Reservations r ON p.ReservationId = p.ReservationId
JOIN Rooms ro ON r.RoomId = ro.Id
WHERE CAST([From] AS date) = CONVERT(date, @StartDate, 105)
END";
migrationBuilder.Sql(sql);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DROP PROC GetGuestsForDate");
}
}
This is a simple SQL code, that first checks if a procedure exists and if so, it deletes it. Then it creates a new procedure with the name GetGuestsForDate
, which will get all arriving guests for a given date.
When the migration will be executed on the database, this stored procedure will be present, which we can see here:
#asp.net core for .net 5 & ef core 5 #ef core 5 #stored procedure #data science
1599214200
Stored procedures are an integral part of any MS SQL database. They are perfect to wrap complicated SQL into a database object, that we can reuse. How to execute a stored procedure that returns data in Entity Framework Core 5? In my last post: Execute a stored procedure with Entity Framework Core 5 I showed how to run a stored procedure, but selecting the data it’s a different kind of story. Let’s have a look.
First of all, we need to add a stored procedure. The best way to do so is to add a database migration with an appropriate SQL. Let’s start by adding a migration with EF Core global tool command:
dotnet ef migrations add spGetGuestsForDate
This will generate a migration, that we can put our SQL into. Let’s see how it may look:
public partial class spGetGuestsForDate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var sql = @"
IF OBJECT_ID('GetGuestsForDate', 'P') IS NOT NULL
DROP PROC GetGuestsForDate
GO
CREATE PROCEDURE [dbo].[GetGuestsForDate]
@StartDate varchar(20)
AS
BEGIN
SET NOCOUNT ON;
SELECT p.Forename, p.Surname, p.TelNo, r.[From], r.[To], ro.Number As RoomNumber
FROM Profiles p
JOIN Reservations r ON p.ReservationId = p.ReservationId
JOIN Rooms ro ON r.RoomId = ro.Id
WHERE CAST([From] AS date) = CONVERT(date, @StartDate, 105)
END";
migrationBuilder.Sql(sql);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DROP PROC GetGuestsForDate");
}
}
This is a simple SQL code, that first checks if a procedure exists and if so, it deletes it. Then it creates a new procedure with the name GetGuestsForDate
, which will get all arriving guests for a given date.
When the migration will be executed on the database, this stored procedure will be present, which we can see here:
#asp.net core for .net 5 & ef core 5 #ef core 5 #stored procedure #data science
1620466520
If you accumulate data on which you base your decision-making as an organization, you should probably think about your data architecture and possible best practices.
If you accumulate data on which you base your decision-making as an organization, you most probably need to think about your data architecture and consider possible best practices. Gaining a competitive edge, remaining customer-centric to the greatest extent possible, and streamlining processes to get on-the-button outcomes can all be traced back to an organization’s capacity to build a future-ready data architecture.
In what follows, we offer a short overview of the overarching capabilities of data architecture. These include user-centricity, elasticity, robustness, and the capacity to ensure the seamless flow of data at all times. Added to these are automation enablement, plus security and data governance considerations. These points from our checklist for what we perceive to be an anticipatory analytics ecosystem.
#big data #data science #big data analytics #data analysis #data architecture #data transformation #data platform #data strategy #cloud data platform #data acquisition
1602668764
Today, the Entity Framework Core team announces the second release candidate (RC2) of EF Core 5.0. This is a feature complete release candidate of EF Core 5.0 and ships with a “go live” license. You are supported using it in production. This is a great opportunity to start using EF Core 5.0 early while there is still time to fix remaining issues. We’re looking for reports of any remaining critical bugs that should be fixed before the final release.
EF Core 5.0 will not run on .NET Standard 2.0 platforms, including .NET Framework.
EF Core is distributed exclusively as a set of NuGet packages. For example, to add the SQL Server provider to your project, you can use the following command using the dotnet tool:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 5.0.0-rc.2.20475.6
#.net #.net core #.net framework #asp.net #c# #entity framework #announcement #asp.net core #entity framework core
1599295620
Stored procedures are an integral part of any MS SQL database. They are perfect to wrap complicated SQL into a database object, that we can reuse. How to execute a stored procedure in Entity Framework Core 5? Let’s have a look.
First of all we need to add a stored procedure. The best way to do so is to add a database migration with an appropriate SQL. Let’s start by adding a migration with EF Core global tool command:
dotnet ef migrations add spUpdateProfilesCountry
This will generate a migration, that we can put our SQL into. Let’s see how it may look:
{
protected override void Up(MigrationBuilder migrationBuilder)
{
var sql = @"
IF OBJECT_ID('UpdateProfilesCountry', 'P') IS NOT NULL
DROP PROC UpdateProfilesCountry
GO
CREATE PROCEDURE [dbo].[UpdateProfilesCountry]
@StardId int
AS
BEGIN
SET NOCOUNT ON;
UPDATE Profiles SET Country = 'Poland' WHERE LEFT(TelNo, 2) = '48' AND Id > @StardId
END";
migrationBuilder.Sql(sql);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DROP PROC UpdateProfilesCountry");
}
}
This is a simple SQL code, that first checks if procedure exists and if so, it deletes it. Then it creates a new procedure with UpdateProfilesCountry
name, which will update Country
column for every Profile
that phone number starts from 48.
When this migration will be run on the database, it will create UpdateProfilesCountry
stored procedure as in my case.
#asp.net core for .net 5 & ef core 5 #ef core 5 #stored procedure
1603238400
Stored procedures are an integral part of any MS SQL database. They are perfect to wrap complicated SQL into a database object, that we can reuse. How to execute a stored procedure in Entity Framework Core 5? Let’s have a look.
First of all we need to add a stored procedure. The best way to do so is to add a database migration with an appropriate SQL. Let’s start by adding a migration with EF Core global tool command:
1
dotnet ef migrations add spUpdateProfilesCountry
This will generate a migration, that we can put our SQL into. Let’s see how it may look:
public partial class spUpdateProfilesCountry : Migration
{
protected override void Up ( MigrationBuilder migrationBuilder )
{
var sql = @"
IF OBJECT_ID(‘UpdateProfilesCountry’, ‘P’) IS NOT NULL
DROP PROC UpdateProfilesCountry
GO
CREATE PROCEDURE [dbo].[UpdateProfilesCountry]
@StardId int
AS
BEGIN
SET NOCOUNT ON;
UPDATE Profiles SET Country = ‘Poland’ WHERE LEFT(TelNo, 2) = ‘48’ AND Id > @StardId
END" ;
migrationBuilder . Sql ( sql );
}
protected override void Down ( MigrationBuilder migrationBuilder )
{
migrationBuilder . Sql ( @“DROP PROC UpdateProfilesCountry” );
}
}
This is a simple SQL code, that first checks if procedure exists and if so, it deletes it. Then it creates a new procedure with UpdateProfilesCountry
name, which will update Country
column for every Profile
that phone number starts from 48.
When this migration will be run on the database, it will create UpdateProfilesCountry
stored procedure as in my case.
There is no dedicated method to run a stored procedure, so in the case where a stored procedure doesn’t return data, we can just invoke it as a raw SQL. This can be achieved like this:
1
2
3
await primeDbContext . Database . ExecuteSqlRawAsync (
“UpdateProfilesCountry @p0” ,
parameters : new [] { minimalProfileId . ToString () });
When I query the database for all numbers starting with 48, I will see that the country has been updated to Poland. This means that our procedure was executed successfully.
BTW. Don’t worry, those are fake data, generated with Bogus 🙂
#asp.net core for .net 5 & ef core 5 #ef core 5 #stored procedure