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 | |
---|---|---|---|
3.1.1 | 159 | 9/14/2024 | |
3.0.0 | 100 | 9/6/2024 | |
2.0.9 | 119 | 9/4/2024 | |
2.0.8 | 111 | 9/4/2024 | |
2.0.7 | 109 | 9/4/2024 | |
2.0.6 | 109 | 9/4/2024 | |
2.0.5 | 106 | 8/17/2024 | |
2.0.4 | 294 | 10/15/2023 | |
2.0.3 | 154 | 10/15/2023 | |
2.0.2 | 149 | 10/13/2023 | |
2.0.1 | 147 | 10/13/2023 | |
2.0.0 | 145 | 10/10/2023 | |
1.0.7 | 167 | 10/7/2023 | |
1.0.6 | 188 | 7/13/2023 | |
1.0.5 | 197 | 7/9/2023 | |
1.0.4 | 192 | 7/7/2023 | |
1.0.3 | 198 | 7/6/2023 | |
1.0.2 | 189 | 7/6/2023 | |
1.0.1 | 189 | 7/6/2023 | |
1.0.0 | 190 | 7/6/2023 |