问题描述
我想用C#中的DAPPER ORM将数据分为两个单独的模型,从一个模型中的列之间的TeamId
到Location
,以及从RowNumber
到PageCount
的另一个模型中的数据.
我相信您要模拟的对象将是:
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public Supervisor Supervisor { get; set; }
public Location Location { get; set; }
}
实际上,您可以使用Dapper最多实现七个对象,基本上您在SQL中会执行以下操作:
public IEnumerable<Team> GetTeams() => dbConnection.Query<Team, Supervisor, Location, Team>(query,
(team, supervisor, location, team) =>
{
team.Supervisor = supervisor,
team.Location = location,
return team;
});
您可以找到有关其多对象映射的文档此处.我应该指出,除非另有说明,否则它会在ID上分开,并且对象在查询结果中出现的顺序也是如此.
I want to split data into two separate models with DAPPER ORM in C#, From TeamId
to Location
between a column in one model and RowNumber
to PageCount
into another sperate model.
I believe what you are trying to simulate would be an object such as:
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public Supervisor Supervisor { get; set; }
public Location Location { get; set; }
}
You can actually achieve this with Dapper up to seven objects, basically what you would do in your SQL would be:
public IEnumerable<Team> GetTeams() => dbConnection.Query<Team, Supervisor, Location, Team>(query,
(team, supervisor, location, team) =>
{
team.Supervisor = supervisor,
team.Location = location,
return team;
});
You can find documentation on their multi object mapping here. I should denote it splits on Id unless specified and the order the objects appear in query result matter.
这篇关于如何使用Dapper ORM将SQL Select查询拆分为两个Model C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!