我有一个具有许多连接对象的应用程序对象。这在.Net世界中很棒,但不幸的是,连接是通过带有复合键的连接表来管理的。是否可以使用多映射方法在短小精灵中映射它?
现在我只使用两个单独的sql语句,但它并不适合我(来自EF方面)。这是我尝试但无法开始工作的一些代码......
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();
我不断得到的错误是“使用splitOn”错误,但我确信这只是冰山一角。如果那里有人有任何想法,我会全力以赴。