tiny-mapper 1.0.0

A tiny object mapper, linq expression translator for dotnet

There is a newer version of this package available.
See the version list below for details.
Install-Package tiny-mapper -Version 1.0.0
dotnet add package tiny-mapper --version 1.0.0
<PackageReference Include="tiny-mapper" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add tiny-mapper --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

TinyMapper

TinyMapper is, as its name implies, a tiny object to object mapping utility. It is very small (less than 300 PLOC), but does some useful things beyond just object conversion, one such example being the ability to translate Linq expression trees from one parameter type to a different type for an underlying query provider.

It's experimental, and very basic. Use at your own risk.

Example configuration:

using static TinyMapper.TinyMapper;

ModelMapper.CreateMap<Foo, Fee>(map => 
{
    map.Property(x=>x.Id, x=>x.FeeId)
       .Property(x=>x.Transaction, x=>x.History, x=> ConversionLogic(x), x=> SomeOtherConversionLogic(x))
}

Example Object Conversion:

var foo = new Foo();
var fee = ModelMapper.Map<Fee>(foo);
Assert.ArEqual(foo.Id, fee.FeeId);

Example Expression Tree Translation:

// My data model only knows Foo as Fee
class MyRepo: IRepo
{
    public IQueryable<Foo> Find(Expression<Func<Foo, bool>> filter)
    {
        // breaks the "set" returns in memory. feel free to improve
        return db.Set<Fee>().Where(ModelMapper.Translate<Foo ,Fee, bool>(filter))
            .ToArray()
            .Select(x=>ModelMapper<Foo>(x))
            .AsQeryable();
    }
}

// elsewhere - will be executed on the db as a query against the Fee table
myRepo.Find(x=>x.Id == 1) 

TinyMapper

TinyMapper is, as its name implies, a tiny object to object mapping utility. It is very small (less than 300 PLOC), but does some useful things beyond just object conversion, one such example being the ability to translate Linq expression trees from one parameter type to a different type for an underlying query provider.

It's experimental, and very basic. Use at your own risk.

Example configuration:

using static TinyMapper.TinyMapper;

ModelMapper.CreateMap<Foo, Fee>(map => 
{
    map.Property(x=>x.Id, x=>x.FeeId)
       .Property(x=>x.Transaction, x=>x.History, x=> ConversionLogic(x), x=> SomeOtherConversionLogic(x))
}

Example Object Conversion:

var foo = new Foo();
var fee = ModelMapper.Map<Fee>(foo);
Assert.ArEqual(foo.Id, fee.FeeId);

Example Expression Tree Translation:

// My data model only knows Foo as Fee
class MyRepo: IRepo
{
    public IQueryable<Foo> Find(Expression<Func<Foo, bool>> filter)
    {
        // breaks the "set" returns in memory. feel free to improve
        return db.Set<Fee>().Where(ModelMapper.Translate<Foo ,Fee, bool>(filter))
            .ToArray()
            .Select(x=>ModelMapper<Foo>(x))
            .AsQeryable();
    }
}

// elsewhere - will be executed on the db as a query against the Fee table
myRepo.Find(x=>x.Id == 1) 

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.0 2,326 9/23/2018
1.0.2 1,187 12/23/2017
1.0.1 222 12/5/2017
1.0.0 250 12/4/2017