编写Dapper查询嵌套对象

| 我有一个代码结构如下:
class Person
{
    Name PersonName;
    int Age;
}

class Name
{
    string FirstName { get; set; }
    string LastName { get; set; }
}
这是我的存储过程,用于填充数据库中的数据。
Create Procedure SpGetAllPersons
As
Select FirstName, LastName, Age from Persons
如何编写从数据库中拉出所有人员的Dapper查询? 例:
List<Person> Persons = DbConn.Query<Person>(\"SpGetAllPersons\", CommandType.StoredProcedure);
    
已邀请:
如果要选择嵌套对象,则需要使用多重映射器。 这应该工作:
List<Person> persons = DbConn.Query<Name,Person,Person>
  (\"SpGetAllPersons\",
     (name,person) => {person.Name = name; return person;} 
     commandType: CommandType.StoredProcedure, 
     splitOn: \"Age\");
多重映射器可以返回任何类型,甚至只是未映射到任何数据库表的聚合类型。 如果要拆分不属于
id
Id
的任何内容,请务必提供ѭ4m参数。     

要回复问题请先登录注册