VOOZH about

URL: https://www.nuget.org/packages/CodeHelper.Core.Database.SqlServer/

⇱ NuGet Gallery | CodeHelper.Core.Database.SqlServer 6.0.4




👁 Image
CodeHelper.Core.Database.SqlServer 6.0.4

dotnet add package CodeHelper.Core.Database.SqlServer --version 6.0.4
 
 
NuGet\Install-Package CodeHelper.Core.Database.SqlServer -Version 6.0.4
 
 
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="CodeHelper.Core.Database.SqlServer" Version="6.0.4" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeHelper.Core.Database.SqlServer" Version="6.0.4" />
 
Directory.Packages.props
<PackageReference Include="CodeHelper.Core.Database.SqlServer" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeHelper.Core.Database.SqlServer --version 6.0.4
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CodeHelper.Core.Database.SqlServer, 6.0.4"
 
 
#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.
#:package CodeHelper.Core.Database.SqlServer@6.0.4
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeHelper.Core.Database.SqlServer&version=6.0.4
 
Install as a Cake Addin
#tool nuget:?package=CodeHelper.Core.Database.SqlServer&version=6.0.4
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

CodeHelper.Core.Database.SqlServer

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?

Support

You can support the work if you want:

Versions

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

Easy explanation

  1. Give a property in your Class a DBField NameQquestions?
  1. Give your Class a DBInfo attribute to easily save the object
  2. Use the given DBField Names in your stored procedures as column name
  3. Use the methods Database.GetData, Database.GetList, Database.ExecuteScalar and Database.Save in all your classes for clean code.
  4. Database.Save saves you a lot of coding.

Advantages

  1. .Net developer team and SQL Server Team can work independent.
  2. The attributes makes sure all teams use the same way of Naming
  3. Reduce code on how to link your query result with your object.

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.

An example of a stored procedure

 SELECT dbo.offers.ID as OfferID, OfferStart as OfferFrom ,... FROM Offers....

An example of code

 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

DBInfo

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

Database.GetData()

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 });

Database.GetList()

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();
 }

Database.ExecuteScalar

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 });
 }

Question?

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. 
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.

Version Downloads Last Updated
6.0.4 665 9/30/2022
6.0.3 602 9/17/2022
6.0.2 579 8/24/2022
6.0.1 587 8/7/2022
6.0.0 581 8/7/2022
5.0.0 581 8/7/2022
1.0.0 601 8/7/2022