Serialize complex properties with Dapper

Is it possible to serialize Dapper.NET complex properties using Json.NET? The object must be serialized and then stored in the column as a string:

public class Person { public string Id { get; set; } public Address Address { get; set; } // store this as string in database ... } public class Address { public string City { get; set; } public string ZipCode { get; set; } } 

Now we do it manually using ADO.NET:

 command.Parameters.AddWithValue("@Id", obj.Id); command.Parameters.AddWithValue("@Address", obj.Address != null ? JsonConvert.Serialize(obj.Address) : (object) DBNull.Value); ... 
+4
source share

All Articles