是否可以使Dapper.NET使用Json.NET序列化复杂属性?该对象应序列化,然后以字符串形式存储到列中:
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; }
}
现在我们使用ADO.NET手动执行此操作:
command.Parameters.AddWithValue("@Id", obj.Id);
command.Parameters.AddWithValue("@Address", obj.Address != null ? JsonConvert.Serialize(obj.Address) : (object) DBNull.Value);
...