I know this general question is addressed in lots of areas but not for this specific scenario. I have the following objects
public class AuditRecord
{
public long Id {get; private set; }
public Collaborator IssuedBy { get; private set; }
}
public class Collaborator
{
public Collaborator(Guid userId, string name, string email)
{
UserId = userId;
Name = name;
Email = email;
}
public Guid UserId { get; }
public string Name { get; }
public string Email { get; }
}
As you can see the IssuedBy
property has a private setter. Is there a Dapper native way to handle this? The typical examples of passing a function that has the parts won't work because of the private accessor.
var resultData = await _connection.QueryAsync<AuditRecord, Collaborator, AuditRecord>(
AUDIT_INSERT_SQL,
(o, collaborator) =>
{
o.IssuedBy = collaborator;
// Error CS0272
// The property or indexer 'AuditRecord.IssuedBy' cannot be used in this
// context because the set accessor is inaccessible
return o;
}
);
Exposing the property as public or adding a method that does the same is essentially violating encapsulation rules.