我有一个包含address对象的公司。SQL返回的是扁平的,我正在尝试让Query<>加载所有的对象。
cnn.Query<Company,Mailing,Physical,Company>("Sproc",
(org,mail,phy) =>
{
org.Mailing = mail;
org.Physical = phy;
return org;
},
new { ListOfPartyId = stringList }, null, true, commandTimeout: null,
commandType: CommandType.StoredProcedure, splitOn: "MailingId,PhyscialId").ToList();
我也不确定我的SplitOn是否正确。我明白了:
使用多映射API时,如果您的密钥不是Id参数名称: splitOn,请确保设置了API参数
建议会很棒的。
Test.cs中的示例并不是代码要求的查询参数。这些需要更新
发布于 2011-08-17 17:29:06
对我来说这是完美的。也许是打字错误?
我看到了PhyscialId
,它看起来确实很像。
class Company
{
public int Id { get; set; }
public string Name { get; set; }
public Mailing Mailing { get; set; }
public Physical Physical { get; set; }
}
class Mailing
{
public int MailingId { get; set; }
public string Name { get; set; }
}
class Physical
{
public int PhysicalId { get; set; }
public string Name { get; set; }
}
public void TestSOQuestion()
{
string sql = @"select 1 as Id, 'hi' as Name, 1 as MailingId,
'bob' as Name, 2 as PhysicalId, 'bill' as Name";
var item = connection.Query<Company, Mailing, Physical, Company>(sql,
(org, mail, phy) =>
{
org.Mailing = mail;
org.Physical = phy;
return org;
},
splitOn: "MailingId,PhysicalId").First();
item.Mailing.Name.IsEqualTo("bob");
item.Physical.Name.IsEqualTo("bill");
}
https://stackoverflow.com/questions/7078478
复制相似问题