Dapper working with Value Objects to perform all DB operations

Viewed 27

I'm working on a large project (.net core 3.1) where it uses Dapper to perform all the DB operations (create, read, update, delete). I was trying to implement Value Objects on my domain where each class represents the tables in the DB.

Example:

//Value object:
public class Address {
    public string Town { get; set; }
    public string Street { get; set; }
    public string Region { get; set; }
    ...
}

[Table("Contact")] //Dapper attribute
public class Contact {
    public Int32 Id { get; set; }
    public string Name { get; set; }
    public Address Address { get; set; }
}

Is there any way, out of the box, to Create/Update/Read these classes to the DB with Dapper?

The only way I found is to create "manually" the command, constructing the query and the object from scratch and then call the Execute method from the Dapper class SqlMapper ( public static int Execute(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null))

I found this Correct use of multimapping in Dapper but only helps the Read part

0 Answers
Related