SQLinq.Dapper.NETStandard
1.0.0
dotnet add package SQLinq.Dapper.NETStandard --version 1.0.0
NuGet\Install-Package SQLinq.Dapper.NETStandard -Version 1.0.0
<PackageReference Include="SQLinq.Dapper.NETStandard" Version="1.0.0" />
paket add SQLinq.Dapper.NETStandard --version 1.0.0
#r "nuget: SQLinq.Dapper.NETStandard, 1.0.0"
// Install SQLinq.Dapper.NETStandard as a Cake Addin
#addin nuget:?package=SQLinq.Dapper.NETStandard&version=1.0.0
// Install SQLinq.Dapper.NETStandard as a Cake Tool
#tool nuget:?package=SQLinq.Dapper.NETStandard&version=1.0.0
SQLinq
SQLinq allows you to use LINQ (Language INtegrated Query) features of .NET to generate Ad-Hoc SQL Queries at runtime.
This allows for easy generation of ad-hoc SQL code using strongly typed LINQ code in .NET in a similar fashion to writing queries with Entity Framework. However, SQLinq is NOT an ORM. SQLinq is a library for generating ad-hoc, strongly typed SQL code at runtime. The generated SQL code can then be executed against a SQL database using either ADO.NET directly, or with Dapper.NET using the SQLinq Dapper nuget package. One of the benefits of SQLinq is that you can write ad-hoc SQL code at runtime that isn't just strongly typed, but benefits from compile time validation as well.
Nuget Package
http://nuget.org/packages/sqlinq
SQLinq Usage
Step 1: Create your data object in code (like the following examples) that matches the database table or view you want to select from. It can either be a class or interface. You can also name the object and/or its properties differently than the database by using the SQLinqTable and SQLinqColumn attributes to specify their name in the database.
[SQLinqTable("PersonTable")]
public class Person
{
public Guid ID { get; set; }
[SQLinqColumn("First_Name")]
public string FirstName { get; set; }
[SQLinqColumn("Last_Name")]
public string LastName { get; set; }
public int Age { get; set; }
}
Step 2: Use LINQ to generate the ad-hoc SQL query necessary.
var query = from d in new SQLinq<Person>()
where d.FirstName.StartsWith("C")
&& d.Age > 18
orderby d.FirstName
select new {
id = d.ID,
firstName = d.FirstName
};
Step 3: Generate the SQL code and necessary query parameter key/value pairs.
var queryResult = query.ToSQL();
// get the full SQL code
var sqlCode = queryResult.ToQuery();
// get the query parameters necessary to execute the above query
var sqlParameters = queryResult.Parameters;
Step 4: Create SqlCommand and set the SQL code and Query Parameters
var cmd = new SqlCommand(dbconnection, sqlCode);
foreach(var p in sqlParameters)
{
cmd.Parameters.AddWithValue(p.Key, p.Value);
}
// now execute the command and get the results from the database
SQLinq.Dapper
SQLinq.Dapper is a small helper library that bridges the gap between SQLinq and Dapper dot net to allow for queries to be performed more easily.
SQLinq.Dapper Usage:
Here's a simple example of using SQLinq.Dapper:
IEnumerable<Person> data = null;
using(IDbConnection con = GetDbConnection())
{
con.Open();
data = con.Query(
from p in new SQLinq<Person>()
where p.FirstName.StartsWith("C") && p.Age > 21
orderby p.FirstName
select p
);
con.Close();
}
// do somthing with the data that was returned
Install SQLinq.Dapper via Nuget
SQLinq.Dapper can also be installed into your project via Nuget!
http://nuget.org/packages/SQLinq.Dapper
Articles
SQLinq: Use LINQ to generate Ad-Hoc, strongly typed SQL queries
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
- Dapper (>= 1.50.5)
- Microsoft.CSharp (>= 4.5.0)
- SQLinq.NETStandard (>= 1.0.0)
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 |
---|---|---|
1.0.0 | 15,898 | 11/27/2018 |