Dapper multiple objects from one row

后端 未结 1 448
太阳男子
太阳男子 2021-02-01 07:12

I have one row coming from the database

select \"John\" Name, 
       \"Male\" Gender,
       20 Age,
       \"Rex\" PetName,
       \"Male\" PetGender,
       5         


        
相关标签:
1条回答
  • 2021-02-01 08:09

    You were pretty close to solution with the Query method. If you don't have an Id column, then you can provide a splitOn argument:

    connection.Query<Person, Pet, Tuple<Person, Pet>>(sql, 
        (person, pet) => Tuple.Create(person, pet), splitOn: "PetName");
    
    0 讨论(0)
提交回复
热议问题