Skip to content

Latest commit

 

History

History
51 lines (47 loc) · 1.73 KB

File metadata and controls

51 lines (47 loc) · 1.73 KB

AutoPocoIO.Repository

Nuget GitHub license Build status codecov

Installation

dotnet add package AutoPocoIO.Repository

How do I get started?

Mark all database data transfer objects with IEntityDto

using AutoMapper;

public class PersonEntityDto : IEntityDto
{
  public void Mapping(Profile profile)
  {
    profile.CreateProjection<PersonEntity, PersonDto>();
    profile.CreateMap<PersonEntity, PersonDto>().ReverseMap();
  }
}

Register services in Startup

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGenericMappingServices(typeof(Program).Assembly);

Usage

Inject Operation type into controller

private readonly IRepositoryServiceAsync<Entity, Dto> _service;
public SampleController(IRepositoryServiceAsync<Entity, Dto> service)
{
    _service = service;
}

Create and load an object from a Database Table or View:

var foo = _service.GetAll();
var bar = _service.GetAll(c => c.Name == "test");

Modify tables with the Dto mapped to the Entity:

await _service.AddAsync(new Dto { Name = "name1" });
await _service.DeleteAsync(1);
await _service.SaveChangesAsync();