Msb.DatabaseContext
2.0.9
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Msb.DatabaseContext --version 2.0.9
NuGet\Install-Package Msb.DatabaseContext -Version 2.0.9
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="2.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Msb.DatabaseContext --version 2.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Msb.DatabaseContext, 2.0.9"
#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=2.0.9 // Install Msb.DatabaseContext as a Cake Tool #tool nuget:?package=Msb.DatabaseContext&version=2.0.9
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Configuration in ASP.NET
Add the connection string in Web.Config file
<appSettings>
<add key="ConnectionString" value="Your database connection string"/>
</appSettings>
Next Create a Class like DataLayer.cs For MSSQL
public class DataLayer : DatabaseContext
{
public DataLayer() : base()
{
ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
}
}
DataLayer.cs For PostgreSQL
public class DataLayer : DatabaseContextNpgsql
{
public DataLayer() : base()
{
ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
}
}
Code Example
public class HomeController : Controller
{
private readonly DatabaseContext database = new DatabaseContext();
public ActionResult Index()
{
ResultData data1 = database.Execute("SPName", new { BookingNo = "45,56" }).FirstOrDefault<ResultData>();
List<ResultData> list1 = database.Execute("SPName", new { BookingNo = "45,56" }).ToList<ResultData>();
ResultData data2 = database.Execute("SPName").FirstOrDefault<ResultData>();
List<ResultData> list2 = database.Execute("SPName").ToList<ResultData>();
string scaler = database.Execute<object,string>("SP_MSB",new { V=450 });
var data1 = database.Execute("SPName", new { BookingNo = "45,56" }).FirstOrDefault();
var list1 = database.Execute("SPName", new { BookingNo = "45,56" }).ToList();
var data2 = database.Execute("SPName").FirstOrDefault();
var list2 = database.Execute("SPName").ToList();
//New feature
SQLParameter parameter = new SQLParameter();
parameter.Add("@BookingNo", "or125");
var list1 = database.Execute("SPName", parameter).ToList();
//Convert class object to DataTable
DataTable dataTable= Utility.ConvertObjectToDataTable(list1);
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
{
private readonly DataLayer _dataLayer;
public HomeController(DataLayer dataLayer)
{
_dataLayer = dataLayer;
}
public IActionResult Index()
{
ResultData data1 = _dataLayer.Execute("SPName", new { BookingNo = "45,56" }).FirstOrDefault<ResultData>();
List<ResultData> list1 = _dataLayer.Execute("SPName", new { BookingNo = "45,56" }).ToList<ResultData>();
ResultData data2 = _dataLayer.Execute("SPName").FirstOrDefault<ResultData>();
List<ResultData> list2 = _dataLayer.Execute("SPName").ToList<ResultData>();
string scaler = _dataLayer.Execute<object,string>("SP_MSB",new { V=450 });
var data1 = _dataLayer.Execute("SPName", new { BookingNo = "45,56" }).FirstOrDefault();
var list1 = _dataLayer.Execute("SPName", new { BookingNo = "45,56" }).ToList();
var data2 = _dataLayer.Execute("SPName").FirstOrDefault();
var list2 = _dataLayer.Execute("SPName").ToList();
//New feature
SQLParameter parameter = new SQLParameter();
parameter.Add("@BookingNo", "or125");
var list1 = _dataLayer.Execute("SPName", parameter).ToList();
//Convert class object to DataTable
DataTable dataTable= Utility.ConvertObjectToDataTable(list1);
}
}
Note :
ResultData is class
Product | Versions 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.
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.5.0)
- Npgsql (>= 8.0.1)
- System.Data.SqlClient (>= 4.8.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
4.0.0 | 44 | 11/29/2024 | |
3.1.1 | 163 | 9/14/2024 | |
3.0.0 | 102 | 9/6/2024 | |
2.0.9 | 121 | 9/4/2024 | |
2.0.8 | 113 | 9/4/2024 | |
2.0.7 | 111 | 9/4/2024 | |
2.0.6 | 111 | 9/4/2024 | |
2.0.5 | 108 | 8/17/2024 | |
2.0.4 | 296 | 10/15/2023 | |
2.0.3 | 156 | 10/15/2023 | |
2.0.2 | 151 | 10/13/2023 | |
2.0.1 | 149 | 10/13/2023 | |
2.0.0 | 147 | 10/10/2023 | |
1.0.7 | 169 | 10/7/2023 | |
1.0.6 | 189 | 7/13/2023 | |
1.0.5 | 199 | 7/9/2023 | |
1.0.4 | 195 | 7/7/2023 | |
1.0.3 | 200 | 7/6/2023 | |
1.0.2 | 191 | 7/6/2023 | |
1.0.1 | 191 | 7/6/2023 | |
1.0.0 | 192 | 7/6/2023 |