Skip to content

Getting Started

Cleve Littlefield edited this page Feb 1, 2016 · 2 revisions

Setup map definition

public class FooModel
{
    public int Id { get; set; }

    public string Name { get; set; }
}

var mapDefinition = new MapDefinition<FooModel>();
mapDefinition.MapType() // Accept default mappings (meaning DB column names )
// See full documentation for more examples on explicit mapping

Basic DbDataReader to POCO

Then once you have executed your reader and have your reader:

var map = CreateMap(reader, mapDefinition);

var list = new List<T>();
while (await reader.ReadAsync())
{
    var item = LoadItem(reader, map);
    list.Add(item);
}

return list;   

Or just use our helper method:

return await reader.LoadListAsync(mapDefinition);

Poco to DbCommand Parameters

First initialize your command setting command text, command type, whatever you want. Then to map parameters:

// model is of type FooModel
command.LoadParameters(model);

Clone this wiki locally