ToreAurstadIt.DapperHelpers.NetStandard 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ToreAurstadIt.DapperHelpers.NetStandard --version 1.1.0
NuGet\Install-Package ToreAurstadIt.DapperHelpers.NetStandard -Version 1.1.0
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="ToreAurstadIt.DapperHelpers.NetStandard" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToreAurstadIt.DapperHelpers.NetStandard --version 1.1.0
#r "nuget: ToreAurstadIt.DapperHelpers.NetStandard, 1.1.0"
#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 ToreAurstadIt.DapperHelpers.NetStandard as a Cake Addin
#addin nuget:?package=ToreAurstadIt.DapperHelpers.NetStandard&version=1.1.0

// Install ToreAurstadIt.DapperHelpers.NetStandard as a Cake Tool
#tool nuget:?package=ToreAurstadIt.DapperHelpers.NetStandard&version=1.1.0

ToreAurstadIT.DapperHelpers.NetStandard

This Nuget package contains assorted helper methods for Dapper. There are already multiple helper libraries for Dapper, but this library will complement missing helper methods that DapperContrib and DapperUtils do not include yet.

To use the helper methods, add a using of the following namespace to your code first to access the public extension methods of the library.

using DapperUtils.ToreAurstadIT;

Now you can access the methods of this lib via your IDbConnection ADO.NET DB Connection instance.

Inner joins via typed lambda expressions

The library supports helpers for joining 2-7 tables via lambda expresisions. The joins are for now inner joins without filtering capability (i.e. all rows are fetched), but this will be included in future versions. If you want to fetch less columns, just make your DTOs non-wide with few columns or add the [NotMapped] attribute to skip them.

An example of inner joins via typed Lambda expression is one key feature of the library. The following integration test against Northwind DB shows how you can inner join against six tables via five join expressions. The join expressions must have this format and make note that we select ALL columns from the tables via all the public properties on your DTO. If you want to specify another tablename for the DTO, use the [Table] attribute from System.ComponentModel.DataAnnotations.Schema namespace. If you want to ignore a property, add the [NotMapped] attribute to the property (column) to skip from the result set.

I will add a filtering capability on this join method and other join types such as left outer joins in the future.

The following example shows how you can join six tables via typed lambda expressions with helper method InnerJoin.


        [Test]
        public void InnerJoinSixTablesWithoutManualSqlReturnsExpected()
        {
            var joinedproductsandcategory = Connection.InnerJoin(
                (Order o, OrderDetail od) => o.OrderID == od.OrderID,
                (Order o, Employee e) => o.EmployeeID == e.EmployeeID,
                (OrderDetail od, Product p) => od.ProductID == p.ProductID,
                (Product p, Category c) => p.CategoryID == c.CategoryID,
                (Product p, Supplier s) => p.SupplierID == s.SupplierID);
            dynamic firstRow = joinedproductsandcategory.ElementAt(0);
            Assert.AreEqual(firstRow.EmployeeID + firstRow.Title + firstRow.OrderID + firstRow.ShipName + firstRow.ProductID.ToString() + firstRow.ProductName + firstRow.CategoryID + firstRow.CategoryName + firstRow.SupplierID + firstRow.CompanyName, "5Sales Manager10248Vins et alcools Chevalier11Queso Cabrales4Dairy Products5Cooperativa de Quesos 'Las Cabras'");
        }

Retrieving paginated data from DB

This example shows how you can retrieve a page from a result set via the helper method GetPage

        [Test]
        public void GetPageReturnsExpected()
        {
            var sql = $"select * from products";
            var productPage = Connection.GetPage<Product>(m => m.ProductID, sql, 0, 5, sortAscending: true).ToList();
            Assert.IsNotNull(productPage);
            productPage?.Should().NotBeEmpty();
            productPage?.Count().Should().Be(5);
            string productIds = string.Join(",", productPage?.Select(x => x.ProductID));
            productIds.Should().Be("1,2,3,4,5");
        }

<hr /> <br /> Reminder Build new versions of this lib

Edit the .nuspec file and bump versions and run:

nuget pack

Then upload nuget package to nuget.org again with new version.

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

This package has no dependencies.

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.6.0 337 7/20/2021
1.5.0 284 7/19/2021
1.4.0 301 7/19/2021
1.3.0 308 7/19/2021
1.2.0 280 7/17/2021
1.1.0 290 7/16/2021
1.0.1 261 7/16/2021

Supported frameworks are any .NET Framework and .NET Core support .NET Standard 2.