Dappir 1.0.2

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

// Install Dappir as a Cake Tool
#tool nuget:?package=Dappir&version=1.0.2

Dappir - more extensions for dapper

=>This is a small tribute to our developer department DAPI; Why the name Dappir?: Dapper + Dapi = Dappir. Departamento de Aprimoramento da Primeira Instância - DAPI

Features

Dappir contains a number of helper methods for inserting, getting, updating and deleting records and on cascade too \o/.

You remember of Contrib, ow yeah, its true, but is not, haha!!!

This is for SQL SERVER still, but we want them for all data bases. do you want help us, do fork now.

The full list of extension methods in Dappir on 'IDbTransaction' right now are:


//we are using this litle interface for facibily, all methods have this interface like constraint
public interface IModel { }

//now we have this methods

//inserts
void Insert<TModel>(TModel entity);
void InsertAll<TModel>(IEnumerable<TModel> listEntity);
void InsertOnCascade<TModel>(TModel entity);

//selects
IEnumerable<TModel> SelectAll<TModel>();
IEnumerable<TModel> Select<TModel>(object filterDynamic);
TModel Select<TModel>(int key);
TModel SelectOnCascade<TModel>(int key);

//updates
void Update<TModel>(TModel entity);
void UpdateAll<TModel>(IEnumerable<TModel> listEntity);
void UpdateOnCascade<TModel>(TModel entity);

//deletes
void Delete<TModel>(int key);
void Delete<TModel>(TModel entity);
void DeleteAll<TModel>(IEnumerable<TModel> listEntity);
void DeleteOnCascade<TModel>(int key);

For these extensions to work, the entity in question MUST have a key property decorate with [Column(IsPrimaryKey = true)].

public class Car
{
    [Column(IsPrimaryKey = true)]
    public int CarId { get; set; }
    public string Name { get; set; }
}

For your entity working with cascade, you must decorate yours property on [Association].

public class Car
{
    [Column(IsPrimaryKey = true)]
    public int CarId { get; set; }
    public string Name { get; set; }
    
    [Association]
    public Carmaker Maker { get; set; }

    [Association]
    public List<Dealership> Dealerships { get; set; }
}

public class Carmaker
{
    [Column(IsPrimaryKey = true)]
    public int CarmakerId { get; set; }
    public int CarId { get; set; }
    public string Name { get; set; }
}

public class Dealership
{
    [Column(IsPrimaryKey = true)]
    public int DealershipsId { get; set; }
    public int CarId { get; set; }
    public string Name { get; set; }
}

CarId Look this is the relationship between entities.

Select methods

Get one specific entity based on id

var car = transaction.Select<Car>(1);

var carmaker = transaction.Select<Carmaker>(1);

var listDealerships = transaction.Select<Dealership>(new { CarId = 1 });

or a list of all entities in the table.

var listDealerships = transaction.SelectAll<DealershipCar>();

or still you can select on cascade, look that:

var car = transaction.SelectOnCascade<Car>(1);

var carmaker = car.Maker;

var listDealerships = car.Dealerships;

\o/ its amazing Yeah, cascade is very nice.

Insert methods

Insert one entity

var car = new Car { Name = "520" };
car.Maker = new Carmaker { "Volvo" };
car.Dealerships = new List<Dealership> 
{ 
    new Dealership { Name = "Veronica Vehicles" }, 
    new Dealership { Name = "Heavy Loader Trucks" } 
};

transaction.Insert(car);

car.Maker.CarId = car.CarId;

transaction.Insert(car.Maker);

car.Dealerships.ForEach(x =>
{
    x.CarId = car.CarId;
    transaction.Insert(x);
})

or a list of entities.

var car = new Car { Name = "520" };
car.Maker = new Carmaker { "Volvo" };
car.Dealerships = new List<Dealership> 
{ 
    new Dealership { Name = "Veronica Vehicles" }, 
    new Dealership { Name = "Heavy Loader Trucks" } 
};

transaction.Insert(car);

car.Maker.CarId = car.CarId;

transaction.Insert(car.Maker);

car.Dealerships.ForEach(x => x.CarId = car.CarId);

transaction.InsertAll(car.Dealerships);

or insert with cascade, more easy:

var car = new Car { Name = "520" };
car.Maker = new Carmaker { "Volvo" };
car.Dealerships = new List<Dealership> 
{ 
    new Dealership { Name = "Veronica Vehicles" }, 
    new Dealership { Name = "Heavy Loader Trucks" } 
};

transaction.InsertOnCascade(car);

Update methods

Update one specific entity

transaction.Update(new Car() { CarId = 1, Name = "Saab" });

or update a list of entities.

transaction.UpdateAll(cars);

and ofcourse, cascade.

transaction.UpdateOnCascade(car);

Delete methods

Delete an entity by the specified [Column(IsPrimaryKey = true)] property

transaction.Delete(new Car() { CarId = 1 });
transaction.Delete<Car>(1);

a list of entities

transaction.DeleteAll(cars);

and our good and friend old cascade

pay attention to the external relations with the car class on use of cascade.

transaction.DeleteOnCascade<Car>(1);

Special Attributes

Dappir makes use of some optional attributes:

  • [Table("Tablename")] - use another table name instead of the name of the class

    [Table ("emps")]
    public class Employee
    {
        [Column(IsPrimaryKey = true)]
        public int EmployeeId { get; set; }
        public string Name { get; set; }
    }
    

if dependencies do not resolve correctly, copy and paste the DappirHelperExtensions class into your project

Product Compatible and additional computed target framework versions.
.NET Framework net35 is compatible.  net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 3.5

  • .NETFramework 4.0

  • .NETFramework 4.6

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.1.6 1,319 11/8/2017
1.1.5 1,011 11/7/2017
1.0.5 1,306 10/28/2017
1.0.4 1,021 10/28/2017
1.0.3 1,004 10/28/2017
1.0.2 1,017 10/28/2017
1.0.1 1,121 10/28/2017
1.0.0 1,021 10/28/2017