我有一家包含地址对象的公司。 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是否正确。我收到消息: When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name: splitOn建议会很棒。Test.cs中的示例不是代码要求的查询参数。这些需要更新 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 对我来说,这很完美...也许是错字?我看到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");}关于c# - dapper -multi-mapping : flat sql return to nested objects,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7078478/ (adsbygoogle = window.adsbygoogle || []).push({}); 10-09 02:49