DeltaWare.SDK.EntityFrameworkCore 5.0.1.1

Suggested Alternatives

DeltaWare.SDK.Extensions.EntityFrameworkCore 7.0.0.1

Additional Details

This package is no longer supported as it has been split and renamed to DeltaWare.SDK.Extensions.EntityFrameworkCore and DeltaWare.SDK.Extensions.EntityFrameworkCore.SqlServer.

There is a newer version of this package available.
See the version list below for details.
dotnet add package DeltaWare.SDK.EntityFrameworkCore --version 5.0.1.1                
NuGet\Install-Package DeltaWare.SDK.EntityFrameworkCore -Version 5.0.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DeltaWare.SDK.EntityFrameworkCore" Version="5.0.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DeltaWare.SDK.EntityFrameworkCore --version 5.0.1.1                
#r "nuget: DeltaWare.SDK.EntityFrameworkCore, 5.0.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DeltaWare.SDK.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=DeltaWare.SDK.EntityFrameworkCore&version=5.0.1.1

// Install DeltaWare.SDK.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=DeltaWare.SDK.EntityFrameworkCore&version=5.0.1.1                

SQL Stored Procedures

This middle-ware is intended to provide a simple and straightforward way of executing stored procedures. The current implementation handles creation of the SQL Command, opening and closing a connection, disposing of instances and mapping the return type.

Supported Return Type

  • Scalar ExecuteScalarAsync<int>();
  • Types ExecuteAsync<MyType>();
  • Lists ExecuteAsync<List<MyType>>();

Executing an SQL Stored Procedure.

NOTE: SQL Stored Procedures can only be executed when using UseSqlServer, otherwise a MethodAccessException will be thrown.

There are presently three ways of assigned parameters to an SQL stored procedure.

  1. Anonymous type mapping
  2. Direct type mapping NOTE: Direct type mapping supports property selection.
  3. SQL Parameters Building

Anonymous Code Mapping

public Task<ReturnType> RunSomethingAsnc(string myParameterA, int myParamaterB, DateTime myParamaterB)
	return _myDbContext
		.RunSqlStoredProcedure("{MyStoredProcedure}")
		.WithParameters(new
		{
		    myParameterA,
		    MYPARAMETERB = myParameterB,
		    MyPARAMETERc = myParameterC
		})
		.ExecuteAsync<ReturnType>();
	}

In the above example the following code will map to.

EXEC [dbo].[MyStoredProcedure]
		@myParameterA = 'Some text',
		@MYPARAMETERB = '42',
		@MyPARAMETERc = '01-01-2012'

Direct Type Mapping

public class MyType
{
	public string Title { get; set; }
	public DateTime endDate { get; set;}
}
public Task<List<ReturnType>> DoSomethingElseAsync(MyType parameterA)
{
	return _myDbContext
		.RunSqlStoredProcedure("{MyOtherStoredProcedure}")
		.WithParameters(parameterA)
		.ExecuteAsync<List<ReturnType>>();
}

In the above example the following code will map to.

EXEC [dbo].[MyOtherStoredProcedure]
		@Title = 'Dr',
		@endDate = '01-01-2012'

Using Property Selection

public Task<List<ReturnType>> DoSomethingElseAsync(MyType parameterA)
{
	return _myDbContext
		.RunSqlStoredProcedure("{MyOtherStoredProcedure}")
		.WithParameters(parameterA, p => new { p.Title })
		.ExecuteAsync<List<ReturnType>>();
}

In the above example the following code will map to.

EXEC [dbo].[MyOtherStoredProcedure]
		@Title = 'Dr'

SQL Parameter Builder

public Task<ReturnType> RunAnotherThingAsync(string myParameterA, int myParamaterB, DateTime myParamaterB)
	return _myDbContext
		.RunSqlStoredProcedure("{MyStoredProcedure}")
		.WithParameters(b => 
		{
			b.AddParameter("@myParameterA", SqlDbType.VarChar, myParameterA);
			b.AddParameter("@MYPARAMETERB", SqlDbType.Int, myParameterB);
			b.AddParameter("@MyPARAMETERc", SqlDbType.Date, myParameterC);			
		})
		.ExecuteAsync<ReturnType>();
	}

In the above example the following code will map to.

EXEC [dbo].[MyStoredProcedure]
		@myParameterA = 'Some text',
		@MYPARAMETERB = '42',
		@MyPARAMETERc = '01-01-2012'

Stored Procedure Options

Set Command Timeout

.RunSqlStoredProcedure("{MyStoredProcedure}", o => 
{
	o.Timeout = 1472;
})
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.