gpt4 book ai didi

c# - 小巧玲珑-多映射 : flat sql return to nested objects

转载 作者:IT王子 更新时间:2023-10-29 04:39:24 24 4
gpt4 key购买 nike

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

最佳答案

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

我看到 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# - 小巧玲珑-多映射 : flat sql return to nested objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com