Msb.DatabaseContext 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package Msb.DatabaseContext --version 1.0.6                
NuGet\Install-Package Msb.DatabaseContext -Version 1.0.6                
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="Msb.DatabaseContext" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Msb.DatabaseContext --version 1.0.6                
#r "nuget: Msb.DatabaseContext, 1.0.6"                
#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 Msb.DatabaseContext as a Cake Addin
#addin nuget:?package=Msb.DatabaseContext&version=1.0.6

// Install Msb.DatabaseContext as a Cake Tool
#tool nuget:?package=Msb.DatabaseContext&version=1.0.6                

Configuration in ASP.NET

Add the connection string in Web.Config file


  <appSettings>
   
   <add key="ConnectionString" value="Your database connection string"/>
  </appSettings>

Code Example

    public class HomeController : Controller
    {

       private readonly DatabaseContext database = new DatabaseContext();
        public ActionResult Index()
        {

            ResultData data1 = database.ExuceuteDataWithParameters<object, ResultData>("SPName", new { BookingNo = "45,56" });
            List<ResultData> list1 = database.ExuceuteListWithParameters<object, ResultData>("SPName", new { BookingNo = "45,56" });

            ResultData data2 = database.ExuceuteDataWithOutParameters<ResultData>("SPName");
            List<ResultData> list2 = database.ExuceuteListWithOutParameters<ResultData>("SPName");

            object scalar = database.ExecuteScalar<object>("SPName", new { Id = 1 }, CommandType.StoredProcedure);
            return View();
        }
}

##Note :

ResultData is class

Configuration in ASP.NET CORE

add the line in appsettings.json file

 "ConnectionStrings": {
    "ConnectionString": "Data Source=Your connenction string"
  }

Next Create a Class like DataLayer.cs

public class DataLayer : DatabaseContext
    {
        public DataLayer(IConfiguration iConfiguration)
        {
            ConnectionString = iConfiguration.GetConnectionString("ConnectionString");
        }
    }

if you used another application(Desktop,Console)

public class DataLayer : DatabaseContext
    {
        public DataLayer()
        {
            ConnectionString = "Your connenction string";
        }
    }

Add new line on ConfigureServices methon in Startup.cs/Program.cs file

services.AddSingleton<DataLayer>();
//if used DOT NET  6 version
builder.Services.AddSingleton<DataLayer>();

Example Code

 public class HomeController : Controller
    {

        public DataLayer DataLayer;

        public HomeController(DataLayer dataLayer)
        {
            DataLayer = dataLayer;
        }

        public IActionResult Index()
        {
            ResultData data1 = DataLayer.ExuceuteWithParameters<object, ResultData>("SPName", new { BookingNo = "45,56" });
            List<ResultData> list1 = DataLayer.ExuceuteListWithParameters<object, ResultData>("SPName", new { BookingNo = "45,56" });

            ResultData data2 = DataLayer.ExuceuteDataWithOutParameters<ResultData>("SPName");
            List<ResultData> list2 = DataLayer.ExuceuteListWithOutParameters<ResultData>("SPName");

            object scalar = DataLayer.ExecuteScalar<object>("SPName", new { Id = 1 },CommandType.StoredProcedure);

            return View();
        }
}

Note :

ResultData is class

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.