Skip to content

Map to an Existing Object

schotime edited this page Nov 10, 2012 · 2 revisions

Using the methods SingleInto, SingleOrDefaultInto, FirstInto and FirstOrDefaultInto it is possible to map columns from the database onto an existing object. Only the columns in the query will be set on the existing object.

public class User 
{
    public int UserId { get;set; }
    public string Email { get;set; }
}

var user = new User() { UserId = 1 };
IDatabase db = new Database("connStringName");
db.SingleOrDefaultInto(user, "select Email from users where userid = @0", 1);