Com.H.Data.Common
2.0.0
See the version list below for details.
dotnet add package Com.H.Data.Common --version 2.0.0
NuGet\Install-Package Com.H.Data.Common -Version 2.0.0
<PackageReference Include="Com.H.Data.Common" Version="2.0.0" />
paket add Com.H.Data.Common --version 2.0.0
#r "nuget: Com.H.Data.Common, 2.0.0"
// Install Com.H.Data.Common as a Cake Addin #addin nuget:?package=Com.H.Data.Common&version=2.0.0 // Install Com.H.Data.Common as a Cake Tool #tool nuget:?package=Com.H.Data.Common&version=2.0.0
Com.H.Data.Common (.net standard 2.0 support)
Adds ExecuteQuery extension methods to DbConntion and DbCommand that return dynamic data result IEnumerable<dynamic>
.
For source code and documentation, kindly visit the project's github page https://github.com/H7O/Com.H.Data.Common
This is the .net standard 2.0 version of the library. If you are using higher .net versions, please use the corresponding latest version number of this library that matches the start version number of the .net you are using. For example, if you are using .net 8, use version 8.x.x.x of this library.
Sample 1
This sample demonstrates how to execute a simple query without parameters on a SQL Server Database. To run this sample, you need to:
- Create a new console application
- Add NuGet package Com.H.Data.Common
- Add NuGet package Microsoft.Data.SqlClient
- Copy and paste the following code into your Program.cs file:
using Com.H.Data.Common;
using System.Data.Common;
using Microsoft.Data.SqlClient;
string conStr = @"connection string goes here";
DbConnection dc = new SqlConnection(conStr);
// ^ note the use of DbConnection instead of SqlConnection. The extension methods
// are defined on DbConnection
var result = dc.ExecuteQuery("select 'John' as name, '123' as phone");
// ^ returns IEnumerable<dynamic>, you can also return IEnumerable<T> where T is your data model class
// by using the ExecuteQuery<T> method which returns IEnumerable<T>
// example: var result = dc.ExecuteQuery<YourDataModelClass>("select 'John' as name, '123' as phone");
foreach (var item in result)
{
System.Console.WriteLine($"name = {item.name}, phone = {item.phone}");
}
Sample 2
This sample demonstrates how to pass parameters to your SQL query
using Com.H.Data.Common;
using System.Data.Common;
using Microsoft.Data.SqlClient;
string conStr = @"your connection string goes here";
DbConnection dc = new SqlConnection(conStr);
// ^ note the use of DbConnection instead of SqlConnection. The extension methods
// are defined on DbConnection
var queryParams = new { name = "Jane" };
// ^ queryParams could be an anonymous object (similar to the example above)
// or the following types:
// 1) IDictionary<string, object>
// 2) Normal object with properties that match the parameter names in the query
// 3) JSON string
// 4) System.Text.Json.JsonElement (useful when building Web APIs, allows passing
// JsonElement input directly from a web client)
// Example 1: var queryParams = new Dictionary<string, object> { { "name", "Jane" } }
// Example 2: var queryParams = new MyCustomParamClass { name = "John" }
// Example 3: var queryParams = "{\"name\":\"Jane\"}"
// Example 4: var queryParams = System.Text.Json.JsonDocument.Parse("{\"name\":\"John\"}").RootElement
var result = dc.ExecuteQuery(@"
select * from (values
('John', '55555'),
('Jane', '44444')) as t (name, phone)
where name = {{name}}", queryParams
);
// ^ note the use of curly braces around the parameter name in the query.
// This is a special syntax that allows you to pass parameters to your query.
// The parameter name must match the property name in the queryParams object.
// It also protects you from SQL injection attacks and is configurable to use other
// delimiters by passing a regular expression
// Example 1: using `[[` and `]]` instead of `{{` and `}}` dc.ExecuteQuery(@"
// select * from (values ('John', '55555'), ('Jane', '44444')) as t (name, phone)
// where name = [[name]]",
// queryParams, @"(?<open_marker>\[\[)(?<param>.*?)?(?<close_marker>\]\])" );
// Example 2: using `|` instead of `{{` and `}}` dc.ExecuteQuery(@"
// select * from (values ('John', '55555'), ('Jane', '44444')) as t (name, phone)
// where name = |name|",
// queryParams, @"(?<open_marker>\|)(?<param>.*?)?(?<close_marker>\|)" );
foreach (var item in result)
{
System.Console.WriteLine($"name = {item.name}, phone = {item.phone}");
}
What other databases this library supports?
Any ADO.NET provider that implements DbConnection and DbCommand classes should work with this library.
What other features this library has?
This small library has several other options that allow for more advanced features that might not be of much use to most, hence samples for those features have been left out in this quick how to
documentation.
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. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
- System.Text.Json (>= 8.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Com.H.Data.Common:
Package | Downloads |
---|---|
Com.H.Threading.Scheduler.VP.Sql
Sql server value processor for Com.H.Threading.Scheduler library |
|
Com.H.Extensions.Logging
Database ILogger implementation |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.0.6 | 115 | 9/5/2024 |
8.0.0.5 | 103 | 9/4/2024 |
8.0.0.4 | 117 | 6/2/2024 |
8.0.0.3 | 128 | 4/17/2024 |
8.0.0.2 | 137 | 3/30/2024 |
8.0.0.1 | 235 | 2/22/2024 |
8.0.0 | 560 | 11/16/2023 |
7.0.0.4 | 481 | 10/26/2023 |
7.0.0.3 | 434 | 10/14/2023 |
7.0.0.2 | 494 | 9/19/2023 |
7.0.0.1 | 541 | 8/24/2023 |
7.0.0 | 548 | 8/23/2023 |
2.0.0 | 348 | 12/19/2023 |
Initial release