I want to map a column value to nested object.
for example in my database table i have:
Users
(
varchar UserName,
varchar Password,
binary Permitions
)
in my code i have:
User{string UserName, string Password, Permition Permitions: {...}}
I want to do something like
db.Query<User>("Select UserName, Password, Permisions PermitionsFromTable
from Users WHERE UserName=@User AND Password =@Password", new { user,
password
}, user =>
{
user.Permitions = new Permition();
user.Permitions.LoadPermitions("PermitionsFromTable");
return user ;
});
it's possible?
There's an overload of Query
that lets you specify more than one type to map to and a result type and you can tell it the column to split on, then you can combine the types. So, something like this should work for what you want.
db.Query<User, byte[], User>(
queryString,
new { user, password },
splitOn: "PermisionsFromTable",
(user, perm) =>
{
user.Permitions = new Permition();
user.Permitions.LoadPermitions(perm);
return user;
});