SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime 1.2.0

There is a newer version of this package available.
See the version list below for details.
Install-Package SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime -Version 1.2.0
dotnet add package SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime --version 1.2.0
<PackageReference Include="SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime --version 1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime, 1.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime as a Cake Addin
#addin nuget:?package=SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime&version=1.2.0

// Install SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime as a Cake Tool
#tool nuget:?package=SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime&version=1.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

EFCore.NodaTime

Adds native support to EntityFrameworkCore for SQL Server for the NodaTime types.

The following types are supported:

  • Instant
  • OffsetDateTime
  • LocalDateTime
  • LocalDate
  • LocalTime
  • Duration

Unit Tests

All types and their methods have unit tests written to verify that the SQL is translated as expected. See individual tests for more information.

Usage

To use, simply install the NuGet package:

Install-Package SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime

Then call the UseNodaTime() method as part of your SqlServer configuration during the UseSqlServer method call:

Using Microsoft.EntityFrameworkCore.SqlServer.NodaTime.Extensions;

options.UseSqlServer("your DB Connection",
                    x => x.UseNodaTime());

DATEADD Support

The SQL DATEADD function is supported for the following types:

  • Instant (extension methods)
  • OffsetDateTime (native and some extension methods)
  • LocalDateTime (native and some extension methods)
  • LocalDate (native and some extension methods)
  • LocalTime (native and some extension methods)
  • Duration (native and some extension methods)

Note: Please add a using statement in order to use the extension methods:

Using Microsoft.EntityFrameworkCore.SqlServer.NodaTime.Extensions;

Supported Methods

  • PlusYears
  • PlusMonths
  • PlusDays
  • PlusHours
  • PlusMinutes
  • PlusSeconds
  • PlusMilliseconds
Using Microsoft.EntityFrameworkCore.SqlServer.NodaTime.Extensions;

// PlusYears
await this.Db.RaceResult
    .Where(r => r.StartTime.PlusYears(1) >= Instant.FromUtc(2019, 7, 1, 1, 0))
    .ToListAsync();

// Translates to: 
// SELECT [r].[Id], [r].[EndTime], [r].[StartTime], [r].[StartTimeOffset] 
// FROM [RaceResult] AS [r] WHERE DATEADD(year, CAST(1 AS int), [r].[StartTime]) >= '2019-07-01T01:00:00.0000000Z'

DATEPART Support

The SQL DATEPART function is supported for the following types:

  • Instant (extension methods)
  • OffsetDateTime (native and some extension methods)
  • LocalDateTime (native and some extension methods)
  • LocalDate (native and some extension methods)
  • LocalTime (native and some extension methods)
  • Duration (native and some extension methods)

Note: Please add a using statement in order to use the extension methods:

Using Microsoft.EntityFrameworkCore.SqlServer.NodaTime.Extensions;

Supported Methods

  • Year
  • Quarter
  • Month
  • DayOfYear
  • Day
  • Week
  • WeekDay
  • Hour
  • Minute
  • Second
  • Millisecond
  • Microsecond
  • Nanosecond
  • TzOffset
  • IsoWeek
Using Microsoft.EntityFrameworkCore.SqlServer.NodaTime.Extensions;

// Compare the 'Year' DatePart
await this.Db.RaceResult
    .Where(r => r.StartTime.Year() == 2019)
    .ToListAsync();

// Translates to: 
// SELECT [r].[Id], [r].[EndTime], [r].[StartTime], [r].[StartTimeOffset] 
// FROM [RaceResult] AS [r] WHERE DATEPART(year, [r].[StartTime]) = 2019

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime:

Repository Stars
ErikEJ/EFCorePowerTools
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization for EF Core
Version Downloads Last updated
6.0.0 1,012 11/8/2021
6.0.0-rc.2.21480.0 227 10/12/2021
6.0.0-rc.1.21452.0 91 9/22/2021
5.0.3 268 11/9/2021
5.0.2 18,856 4/14/2021
5.0.1 7,606 11/28/2020
5.0.0 563 11/10/2020
3.1.2 80 11/9/2021
3.1.1 8,245 11/28/2020
3.1.0 1,377 11/10/2020
1.3.3 408 10/20/2020
1.3.2 1,000 9/25/2020
1.3.1 1,210 9/7/2020
1.3.0 3,775 3/19/2020
1.2.0 541 3/3/2020