1

I have an application object which has many connection objects. This is great in the .Net world but unfortunately the join is managed via a join table with a composite key. Is it possible to map this in dapper using a multi-mapping approach?

For now I am just using two seperate sql statements, but it doesn't sit well with me ( coming from the EF side of things ). Here is some code I tried but could not get to work...

public class Application
{
    public int ApplicationID { get; set; }
    public string Name { get; set; }
    public string Prefix { get; set; }

    public List<Connection> Connections { get; set; }
}

public class ApplicationConnection
{
    public int ApplicationID { get; set; }
    public int ConnectionID { get; set; }
}

public class Connection
{
    public int ConnectionID { get; set; }
    public string ConnectionString { get; set; }
}

var tsql = @"SELECT A.*,C.*
                        FROM [Application] A
                        INNER JOIN [ApplicationConnections] AC on A.ApplicationID = AC.ApplicationID
                        INNER JOIN [Connections] C ON AC.ConnectionID = C.ConnectionID
                        WHERE A.ApplicationID = 122";
            var results = connection.Query<Application, List<Connection>, Application>(tsql, 
                (appl, conn) => { 
                    appl.Connections = conn; return appl; 
                }, 
                splitOn: "ApplicationID,ConnectionID").First();

The error i keep getting is the "use splitOn" error, but I'm sure that is just the tip of the iceberg here. If anyone out there has any ideas, I'm all ears.

Mark Redfern
  • 357
  • 1
  • 3
  • 24
  • 1
    That *looks* about right; what are the full set of columns coming back from the raw query? So I can try to repro? – Marc Gravell Nov 05 '12 at 20:15
  • 1
    @MarcGravell I have just stuck with the 2 sql calls ( batched the 2 ) so no worries trying to sort this out. But can I just say that I have moved the entire front end away from EF 4.0 and onto dapper and have taken render times from avg of 3.7 seconds to an avg of .6 seconds. You are a legend and I humbly thank you for this awesome tool. – Mark Redfern Dec 07 '12 at 09:24

0 Answers0