-1

Is there a way with the dapperexstension mapping to map an object to a value (id) when the object is a property of another object. Here is an example.

public class Contact
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Address Address { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public string Street { get; set; }
}

The table in the database for Contact will have this 3 columns

  • Id
  • Name
  • AddressId

So when I save the Contact with the connection.Insert<> function I want the Address be converted to Address.Id and mapped to the AddressId column in the Contact table.

I know that I can add a AddressId property in my Contact class and then it will be saved. But then I pollute my Contact class only to make it used by Dapper. There is also the way to not use the connection.Insert method but instead write a Sql Insert statement and use that in a connection.Query. But then I must remember to change the SQL Statement as soon as I change the Contact class.

So I am looking for something like this.

Map(m => m.Address).Columns("AddressId").UseValue(m.Id);
Cœur
  • 37,241
  • 25
  • 195
  • 267
Magnus Gladh
  • 1,817
  • 4
  • 20
  • 31

1 Answers1

0

DapperExtensions is a simple orm overlay. We do not currently have any plans to support aggregate objects.

Thad
  • 1,518
  • 2
  • 21
  • 37