DvBCrud.EFCore 5.1.0

dotnet add package DvBCrud.EFCore --version 5.1.0
NuGet\Install-Package DvBCrud.EFCore -Version 5.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="DvBCrud.EFCore" Version="5.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DvBCrud.EFCore --version 5.1.0
#r "nuget: DvBCrud.EFCore, 5.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 DvBCrud.EFCore as a Cake Addin
#addin nuget:?package=DvBCrud.EFCore&version=5.1.0

// Install DvBCrud.EFCore as a Cake Tool
#tool nuget:?package=DvBCrud.EFCore&version=5.1.0

DvBCrud.EFCore

CRUD functionality using Entity Framework Core.

Table of Contents

How it works

DvBCrud.EFCore streamlines the process of developing a Code-First database by implementing basic CRUD functionality through using generics and polymorphism.

All CRUD functionality is already written, fully tested and available.

Getting started

When you've installed the library, below is an example for defining a Repository for AnyEntity.

1. Create the entity

Create the entity by defining its Id type (int).

AnyEntity.cs

public class AnyEntity : IEntity<long>
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]]
    public long Id { get; set; }
    
    public string? AnyString { get; set; }
}

2. Add it to your DbContext

AnyDbContext.cs

public class AnyDbContext : CrudDbContext
{
    public AnyDbContext()
    {
    }

    public DbSet<AnyEntity> AnyEntities { get; set; }
}

3. Create the model

public class AnyModel
{
    public long Id { get; set; } = "";
    public string? AnyString { get; set; }
}

4. Create the mapper

public class AnyMapper : IAnyMapper
{
    public AnyModel ToModel(AnyEntity entity) =>
        new()
        {
            Id = entity.Id,
            AnyString = entity.AnyString
        };

    public AnyEntity ToEntity(AnyModel model) =>
        new()
        {
            Id = model.Id,
            AnyString = model.AnyString
        };

    public void UpdateEntity(AnyEntity source, AnyEntity destination)
    {
        destination.AnyString = source.AnyString;
    }
}

5. Create the repository

Create the repository by defining its entity type (AnyEntity), the entity's Id type (long) and the DbContext type (AnyDbContext).

AnyRepository.cs

public class AnyRepository : Repository<AnyEntity, long, AnyDbContext, AnyMapper, AnyModel>
{
    public AnyRepository(AnyDbContext context, AnyMapper mapper) : base(context, mapper)
    {
    }
}

6. Use it

After you've injected a new AnyRepository into your application's Startup.cs, you can use it like so:

AnyService.cs

public class AnyService
{
    private readonly AnyRepository _anyRepository;

    public AnyClass(AnyRepository anyRepository)
    {
        this.anyRepository = anyRepository;
    }

    public void CreateAnyEntity(string str)
    {
        var entity = new AnyEntity 
        {
            AnyString = str
        };

        anyRepository.Create(entity);
    }
}
Product 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DvBCrud.EFCore:

Package Downloads
DvBCrud.EFCore.API

Package Description

DvBCrud.EFCore.Services

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.1.0 138 9/24/2023
5.1.0-rc.2 63 9/23/2023
5.1.0-rc.1 54 9/23/2023
5.1.0-alpha.2 59 9/23/2023
5.1.0-alpha.1 67 7/10/2023
5.0.1 135 7/10/2023
5.0.1-rc.1 70 7/10/2023
5.0.0 139 7/9/2023
5.0.0-rc.1 69 7/9/2023
5.0.0-alpha.2 68 7/9/2023
5.0.0-alpha.1 71 7/9/2023
4.0.4 211 6/28/2023
4.0.3 205 6/20/2023
4.0.2 217 5/3/2023
4.0.1 362 2/18/2023
4.0.0 246 2/18/2023
4.0.0-rc.9 137 1/31/2023
4.0.0-rc.8 103 1/31/2023
4.0.0-rc.7 98 1/31/2023
4.0.0-rc.6 104 1/31/2023
4.0.0-rc.5 96 1/31/2023
4.0.0-rc.4 106 1/31/2023
4.0.0-rc.3 107 1/29/2023
4.0.0-rc.2 111 9/11/2022
4.0.0-rc.1 106 9/10/2022
4.0.0-alpha.6 109 9/10/2022
4.0.0-alpha.5 106 9/10/2022
4.0.0-alpha.4 96 9/9/2022
4.0.0-alpha.2 137 7/5/2022
4.0.0-alpha.1 140 7/5/2022
3.2.1-rc.1 116 7/5/2022
3.2.0 813 6/26/2022
3.2.0-rc.3 116 6/26/2022
3.2.0-rc.2 118 6/26/2022
3.2.0-rc.1 117 6/26/2022
3.1.1 651 6/21/2022
3.1.1-rc.1 114 6/18/2022
3.1.0 675 6/18/2022
3.1.0-rc.2 105 6/18/2022
3.1.0-rc.1 127 5/27/2022
3.0.0 700 5/27/2022
3.0.0-alpha.2 134 4/25/2022
2.0.7 769 1/31/2022
2.0.6 624 1/30/2022
2.0.5 570 1/28/2022
2.0.4 558 1/28/2022
2.0.3 565 1/28/2022
2.0.2 416 1/28/2022
1.2.1 666 1/13/2022
1.2.0 470 2/25/2021
1.1.0 452 2/16/2021
1.0.2 444 1/29/2021
1.0.1 478 1/29/2021
1.0.0 487 1/28/2021