seguir funcionando en "Al utilizar las API multi-mapeo asegurar que establecer el parámetro splitOn si tiene teclas que no sean Id" error para el siguiente código de bloque:Dapper Edición Multi-mapeo
var accounts = DbConnection.Query<Account, Branch, Application, Account>(
"select Accounts.*, SplitAccount = '', Branches.*, SplitBranch = '', Applications.*" +
" from Accounts" +
" join Branches" +
" on Accounts.BranchId = Branches.BranchId" +
" join Applications" +
" on Accounts.ApplicationId = Applications.ApplicationId" +
" where Accounts.AccountId <> 0",
(account, branch, application) =>
{
account.Branch = branch;
account.Application = application;
return account;
}, splitOn : "SplitAccount, SplitBranch"
).AsQueryable();
I' m usando SplitAccount y SplitBranch para splitOn como solución temporal.
Em I missing algo?
Gracias
Editar:
he limpiado mi prueba un poco, a continuación es una versión ligera de clases y una nueva consulta:
public class AccountLight
{
public int AccountId { get; set; }
public string AccountNumber { get; set; }
public BranchLight Branch { get; set; }
public ApplicationLight Application { get; set; }
}
public class BranchLight
{
public int BranchId { get; set; }
public string BranchNumber { get; set; }
}
public class ApplicationLight
{
public int ApplicationId { get; set; }
public string ApplicationCode { get; set; }
}
var accounts2 = DbConnection.Query<AccountLight, BranchLight, ApplicationLight, AccountLight>(
"select Accounts.AccountId, Accounts.AccountNumber," +
" Branches.BranchId, Branches.BranchNumber," +
" Applications.ApplicationId, Applications.ApplicationCode" +
" from Accounts" +
" inner join Branches" +
" on Accounts.BranchId = Branches.BranchId" +
" inner join Applications" +
" on Accounts.ApplicationId = Applications.ApplicationId" +
" where Accounts.AccountId <> 0",
(account, brach, application) =>
{
account.Branch = brach;
account.Application = application;
return account;
},
commandType: CommandType.Text,
splitOn: "AccountId, BranchId"
).AsQueryable();
su solución está bien ... ¿qué claves primaria tiene usted sobre las tablas ? –
Sam, gracias por la respuesta. A continuación están las claves: Cuenta: AccountId como PK, BranchId y ApplicationId como FK Sucursal: BranchId como PK Aplicación: ApplicationId como PK –
Otra nota: Funciona si elimino la aplicación. –