TinyHelpers.EntityFrameworkCore
3.0.3
See the version list below for details.
dotnet add package TinyHelpers.EntityFrameworkCore --version 3.0.3
NuGet\Install-Package TinyHelpers.EntityFrameworkCore -Version 3.0.3
<PackageReference Include="TinyHelpers.EntityFrameworkCore" Version="3.0.3" />
paket add TinyHelpers.EntityFrameworkCore --version 3.0.3
#r "nuget: TinyHelpers.EntityFrameworkCore, 3.0.3"
// Install TinyHelpers.EntityFrameworkCore as a Cake Addin #addin nuget:?package=TinyHelpers.EntityFrameworkCore&version=3.0.3 // Install TinyHelpers.EntityFrameworkCore as a Cake Tool #tool nuget:?package=TinyHelpers.EntityFrameworkCore&version=3.0.3
Tiny Helpers for Entity Framework Core
A collection of helper methods and classes for Entity Framework Core that I use every day. I have packed them in a single library to avoid code duplication.
Installation
The library is available on NuGet. Just search for TinyHelpers.EntityFrameworkCore in the Package Manager GUI or run the following command in the .NET CLI:
dotnet add package TinyHelpers.EntityFrameworkCore
Usage
Converters
The library provides some Value Converters to handle data types that are not natively supported by Entity Framework Core. They can be explicitly used calling the HasConversion method, or automatically via some extension methods:
// using TinyHelpers.EntityFrameworkCore.Extensions;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>(builder =>
{
builder.Property(x => x.Title).HasMaxLength(80).IsRequired();
builder.Property(x => x.Content).IsRequired();
// Date is a DateOnly property (.NET 6 or 7).
//builder.Property(x => x.Date).HasDateOnlyConversion();
// Time is a TimeOnly property (.NET 6 or 7).
//builder.Property(x => x.Time).HasTimeOnlyConversion();
/* JSON SUPPORT */
// For .NET 6:
// Reviews is a complex type, this Converter will automatically JSON-de/serialize it
// in a string column.
// builder.Property(x => x.Reviews).HasJsonConversion();
// For .NET 7 or higher:
builder.OwnsMany(x => x.Reviews).ToJson();
/* COLLECTION OF PRIMITIVE TYPES */
// For .NET 6 and 7:
//builder.Property(x => x.Authors).HasArrayConversion();
// For .NET 8
// The support for collection of primitive types is built-in.
});
}
Query Filters
The library provides an extension method that allows to apply a global Query Filter to entities:
public abstract class DeletableEntity
{
public bool IsDeleted { get; set; }
}
public class Person : DeletableEntity { }
public class City: DeletableEntity { }
public class PhoneNumber : DeletableEntity { }
// using TinyHelpers.EntityFrameworkCore.Extensions;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Apply a filter to all the entities that inherit (directly or indirectly) from DeletableEntity.
modelBuilder.ApplyQueryFilter<DeletableEntity>(e => !e.IsDeleted);
}
Contributing
The project is constantly evolving. Contributions are welcome. Feel free to file issues and pull requests on the repo and we'll address them as we can.
Warning Remember to work on the develop branch, don't use the master branch directly. Create Pull Requests targeting develop.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
-
net6.0
- Microsoft.EntityFrameworkCore.Relational (>= 6.0.26)
- TinyHelpers (>= 3.0.2)
-
net7.0
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.15)
- TinyHelpers (>= 3.0.2)
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.1)
- TinyHelpers (>= 3.0.2)
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 |
---|---|---|
3.0.27 | 1,103 | 10/9/2024 |
3.0.25 | 396 | 9/2/2024 |
3.0.24 | 638 | 7/10/2024 |
3.0.22 | 166 | 6/19/2024 |
3.0.19 | 1,501 | 5/15/2024 |
3.0.18 | 267 | 5/14/2024 |
3.0.17 | 143 | 5/9/2024 |
3.0.14 | 5,429 | 3/26/2024 |
3.0.12 | 341 | 2/27/2024 |
3.0.8 | 989 | 2/14/2024 |
3.0.6 | 232 | 2/12/2024 |
3.0.3 | 3,175 | 1/11/2024 |
3.0.2 | 6,339 | 11/21/2023 |
2.0.21 | 12,871 | 9/4/2023 |
2.0.20 | 4,216 | 6/29/2023 |
2.0.19 | 884 | 6/14/2023 |
2.0.18 | 3,836 | 4/12/2023 |
2.0.17 | 584 | 4/10/2023 |
2.0.16 | 1,891 | 3/27/2023 |
2.0.14 | 10,520 | 3/15/2023 |
2.0.13 | 1,241 | 3/1/2023 |
2.0.12 | 1,470 | 2/21/2023 |
2.0.10 | 4,228 | 1/11/2023 |
2.0.9 | 629 | 1/9/2023 |
2.0.4 | 951 | 11/30/2022 |
1.0.76 | 2,073 | 10/31/2022 |
1.0.72 | 6,840 | 9/21/2022 |
1.0.61 | 9,735 | 7/25/2022 |
1.0.59 | 1,059 | 6/30/2022 |
1.0.57 | 790 | 6/21/2022 |
1.0.56 | 1,570 | 6/2/2022 |
1.0.52 | 9,824 | 3/28/2022 |
1.0.48 | 1,534 | 2/7/2022 |
1.0.45 | 4,034 | 1/25/2022 |
1.0.43 | 767 | 1/20/2022 |
1.0.34 | 970 | 1/7/2022 |