[英]dapper -multi-mapping: flat sql return to nested objects
我有一家公司,地址为 object。 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 参数名称:splitOn
建议会很棒。
Test.cs 中的示例不是代码要求作为查询参数的内容。 这些需要更新
对我来说这很完美......也许是一个错字?
我看到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");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.