20

我有一家包含地址对象的公司。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 中的示例不是代码要求作为查询参数的内容。这些需要更新

4

1 回答 1

15

对我来说,这很完美……也许是错字?

我看到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");

}
于 2011-08-17T09:29:06.240 回答