为嵌套对象编写简洁的查询
我的代码结构如下:
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 查询来从数据库中提取所有人员?
示例:
列表<人员> Persons = DbConn.Query
I have a code Structure as below:
class Person
{
Name PersonName;
int Age;
}
class Name
{
string FirstName { get; set; }
string LastName { get; set; }
}
Here is my Stored Proc which populates the data from Database.
Create Procedure SpGetAllPersons
As
Select FirstName, LastName, Age from Persons
How do I write Dapper query which pulls all the Person from Database?
Example:
List<Person> Persons = DbConn.Query<Person>("SpGetAllPersons", CommandType.StoredProcedure);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要选择嵌套对象,则需要使用多重映射器。
这应该可行:
多重映射器可以返回任何类型,甚至只是未映射到任何数据库表的聚合类型。
如果您打算拆分任何不名为
id
或Id
的内容,则提供splitOn
参数非常重要。You need to use the multi mapper if you want to select nested objects.
This should work:
The multi-mapper can return any type, even just an aggregate type that is not mapped to any db table.
It is important to supply the
splitOn
param if you intend to split on anything that is not calledid
orId
.