[英]One to One Qry mapping
I'm trying a quite simple mapping using Dapper. 我正在尝试使用Dapper进行非常简单的映射。 It is kind of One to One result set.
这是一对一结果集。 Here is the simplified version of what I would like to do:
这是我想做的简化版本:
Classes: 类:
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string Town { get; set; }
}
I get the data from a View/Strored Proc like this: 我从View / Strored Proc中获取数据,如下所示:
SELECT street, name, lastname, town from someProc
Is there a way to map this in one step, maybe like this? 有没有办法一步一步地映射它,也许是这样?
//trying to get a List of Persons including mapped Addresses
connection.Query<Person>()
Any suggestions? 有什么建议么?
I figured it out by myself... So for those googling this: 我自己弄清楚了...所以对于那些谷歌搜索:
Combine Dapper.Mapper (NuGet package) and a SplitOn field in your result set. 在结果集中组合Dapper.Mapper(NuGet程序包)和SplitOn字段。
The result data should be ordered by objects (columnwise) and you can either use an Id or a "virtual field" ('' as id) as a splitter. 结果数据应按对象(按列)排序,并且您可以使用ID或“虚拟字段”(“作为ID”)作为分隔符。
The "3rd object" idea is stupid. “第三个对象”的想法很愚蠢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.