![]() |
VOOZH | about |
dotnet add package CodeHelper.Core.Database.SqlServer --version 6.0.4
NuGet\Install-Package CodeHelper.Core.Database.SqlServer -Version 6.0.4
<PackageReference Include="CodeHelper.Core.Database.SqlServer" Version="6.0.4" />
<PackageVersion Include="CodeHelper.Core.Database.SqlServer" Version="6.0.4" />Directory.Packages.props
<PackageReference Include="CodeHelper.Core.Database.SqlServer" />Project file
paket add CodeHelper.Core.Database.SqlServer --version 6.0.4
#r "nuget: CodeHelper.Core.Database.SqlServer, 6.0.4"
#:package CodeHelper.Core.Database.SqlServer@6.0.4
#addin nuget:?package=CodeHelper.Core.Database.SqlServer&version=6.0.4Install as a Cake Addin
#tool nuget:?package=CodeHelper.Core.Database.SqlServer&version=6.0.4Install as a Cake Tool
CodeHelper.Core.Database.SqlServer is a modern lightweight database mapper for .NET Reduce the code and map easily your stored procedures to a object, set value of an object from the database, get lists from database and more....
##Qquestions?
You can support the work if you want:
6.0.3 : GetList excepts SQL queries (next to stored Prcoedures) 6.0.2 : .net6 : Generic Delete function has been added (backwards compatibl). See documentation to link KeyFields 6.0.1 : .net6 5.0.0 : .net5 1.0.0 : .net Core 3.1
Ex. Adding a field to a table, the DB team updated the Stored Procedures/Views, gives the columnname to the development team. The devlopment team adds the property to the class and add a DBField attribute with the given columnname Result: Everything works.
SELECT dbo.offers.ID as OfferID, OfferStart as OfferFrom ,... FROM Offers....
using CodeHelper.Core.Database.Attributes;
using CodeHelper.Core.Database.SqlServer;
public class BaseClass
{
#region Properties
public static string DBConnString { get { return Environment.GetEnvironmentVariable("DbConnString"); } }
#endregion
#region Public Methods
public virtual void Save()
{
Database.Save(this, DBConnString);
}
#endregion
}
[DBInfo("dbo.OfferSave", "OfferID")]
public class Offer : BaseClass
{
#region Properties
[DBField("OfferID")] public Int64 ID { get; set; }
[DBField("LocationID")] public Int64 LocationID { get; set; }
[DBField("BusinessTypeID",false)] public Int64 BusinessTypeID { get; set; } = 1;
[DBField("OfferFrom")] public DateTime OfferStart { get; set; } = System.DateTime.Today;
[DBField("OfferTo")] public DateTime OfferEnd { get; set; } = System.DateTime.Today.AddMonths(1);
[DBField("OfferTitle")] public string Title { get; set; } = "";
[DBField("OfferDescription")] public string Description { get; set; } = "";
#endregion
#region Constructors
public Offer() { }
public Offer(Int64 offerId)
{
Database.GetData(this, DBConnString, "dbo.OfferGetById", new object[] { "OfferID", offerId });
}
#endregion
#region Public Methods
static public Int32 GetNbDealsForUrl(string url)
{
return (Int32)Database.ExecuteScalar("dbo.OfferGetNbForUrl", DBConnString, new string[] { "Url", url });
}
#endregion
#region Static Public Methods
static public List<Offer> SearchOffers(string searchString, int offetX =0, int rowsX = 25)
{
return Database.GetList(typeof(Offer), DBConnString, "[dbo].[OffersSearch]", new object[] { "SearchString", searchString, "OffsetX", offetX, "RowsX", rowsX }).Cast<Offer>().ToList();
}
#endregion
}
The value {CONTACTNAME} can be anything. This value will be used in your text
The DBInfo attribute on the Class level accepts the Save Stored Procedure and the return value (In case the save stored procedure returns a value). The DBField attributes sets the Column name the stored procedure returns. The saveToDB properties of the DBField (true or false) indicates if the Save method will use the Object property to save or not.
The Function Save (often placed in a base class), will take automatically the DBInfo Attribute values, check the DBField Properties of the Object and execute the stored procedure with the parameters The Save function in the base class is virtual, this way you override the function, add extra functionalities and call base.Save()
In this example, when calling the MyObject.Save() method, the Stored Procedure "dbo.OfferSave" will be executed with the 6 parameters and return the new OfferID
Gets the data from the database, and set the object value with the query result, using the DBField attribute DBConnString: the database connection string or the name of the environment variable containing the database connection string myObject: the object you want to fill in (can be an object or this) new object[]: Contains the parameters you like to send to the stored procedure. "FieldName1", FieldValue1, "FieldName2", FieldValue2,... or null
Database.GetData(myObject, DBConnString, "dbo.OfferGetById", new object[] { "OfferID", offerId });
Optimize your database stored procedure and use the GetList to return the query results. DBConnString: the database connection string or the name of the environment variable containing the database connection string new object[]: Contains the parameters you like to send to the stored procedure. "FieldName1", FieldValue1, "FieldName2", FieldValue2,... or null
static public List<Offer> SearchOffers(string searchString, int offetX =0, int rowsX = 25)
{
return Database.GetList(typeof(Offer), DBConnString, "[dbo].[OffersSearch]", new object[] { "SearchString", searchString, "OffsetX", offetX, "RowsX", rowsX }).Cast<Offer>().ToList();
}
Optimize your database stored procedure and use the ExecuteScalar to easily execute and get a value. DBConnString: the database connection string or the name of the environment variable containing the database connection string new object[]: Contains the parameters you like to send to the stored procedure. "FieldName1", FieldValue1, "FieldName2", FieldValue2,... or null
static public Int32 GetNbDealsForUrl(string url)
{
return (Int32)Database.ExecuteScalar("dbo.OfferGetNbForUrl", DBConnString, new string[] { "Url", url });
}
Frederik van Lierde https://twitter.com/@frederik_vl/
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.