I have four classes where one is parent node and three are child nodes. In which PayorState Class and PayorAddressType Class is mapped correctly. I want to map IsAddressPrimary Class same as other one. please help me.
public class PayorAddress
{
public int PayorId { get; set; }
public IsAddressPrimary IsAddressPrimary { get; set; }
public PayorAddressType AddressType { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string City { get; set; }
public PayorState State { get; set; }
public string ZipCode { get; set; }
public int AddressTypeId { get; set; }
public int StateId { get; set; }
}
public class PayorState
{
public int StateId { get; set; }
public string StateName { get; set; }
}
public class IsAddressPrimary
{
public bool Value { get; set; }
public string Text { get; set; }
}
public class PayorAddressType
{
public int AddressTypeId { get; set; }
public string Description { get; set; }
}
await using var conn_payoraddr = new SqlConnection(_connectionString.Value);
string query = "Select t1.*,t2.Id as 'StateId',t2.StateName,t3.Id as 'AddressTypeId',t3.Description, Case When t1.IsPrimary=0 then 'No' else 'Yes' end as 'Text',t1.IsPrimary as 'Value' from PayorAddress t1 LEFT JOIN types.StateAbbrev t2 on t1.StateId=t2.Id LEFT JOIN types.AddressType t3 on t1.AddressTypeId=t3.Id where PayorId=@Id";
var result_addr = await conn.QueryAsync<PayorAddress, PayorState, PayorAddressType, PayorAddress>(
query,
(Address, state, addresstype) =>
{
Address.State = state;
Address.AddressType = addresstype;
return Address;
},
new { Id = id },
splitOn: "StateId,AddressTypeId"
);