使用dapper返回对象列表,每个父母包含两个其他对象
我是Dapper的新手,并有一个3型模型类示例。 SQL数据库具有下面每个模型的关联表。
我的目的是填充作业对象列表(即作业表中的所有记录),每个记录都包含其关联状态&客户端对象。使用Dapper将如何实现?
感谢您提供的任何帮助!
SQL将是:
选择j。*,s。*,c。 >
模型是:
public class StatusModel
{
public int Id { get; set; }
public string StatusName { get; set; }
}
public class ClientModel
{
public int Id { get; set; }
public string ClientName { get; set; }
}
public class JobModel
{
public int Id { get; }
public string Description { get; set; }
public StatusModel Status {get; set; }
public ClientModel Client { get; set; }
}
I'm new to Dapper, and have a 3 model class example. The SQL Database has associated tables for each model below.
My aim is to populate a list of Job objects (ie. all records in the Job table), each containing its associated Status & Client objects. How would this be achieved using Dapper?
Thank you kindly for any help you can give me!
The SQL will be :
SELECT j.*, s.*, c.* FROM Job j INNER JOIN Status s ON j.StatusId = s.Id INNER JOIN Client ON j.ClientId = c.Id;
The models are :
public class StatusModel
{
public int Id { get; set; }
public string StatusName { get; set; }
}
public class ClientModel
{
public int Id { get; set; }
public string ClientName { get; set; }
}
public class JobModel
{
public int Id { get; }
public string Description { get; set; }
public StatusModel Status {get; set; }
public ClientModel Client { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Dapper的Multimap功能。
您可以阅读更多在这里。
You can use Dapper's multimap feature.
You can read more here.