问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/58870494/how-to-split-a-sql-select-query-into-two-model-c-sharp-with-dapper-orm