У меня в коде есть следующие модели:
Код: Выделить всё
public class PersonModel
{
public int Id { get; set; }
public string FullName { get; set; }
public DepartmentModel Department { get; set; }
}
public class DepartmentModel
{
public int Id { get; set; }
public string Name { get; set; }
}
Код: Выделить всё
public Task GetPeople(string connectionString)
{
using var connection = new SqlConnection(connectionString);
var query = "Select People.Id, People.FullName, Department.Name FROM People LEFT JOIN Departments ON People.DepartmentId = Departments.Id";
return await connection.QueryAsync(query, (person, department) => {
person.Department = department;
return person;
},
splitOn: "Id" );
}
Есть ли какой-нибудь способ добиться этого?
Напишите такой код неудачно:
Код: Выделить всё
public Task GetPeople(string connectionString, string query)
{
using var connection = new SqlConnection(connectionString);
return await connection.QueryAsync(query, (model, subModel) => {
model.subModel= subModel; //
Подробнее здесь: [url]https://stackoverflow.com/questions/79291663/using-dapper-one-to-many-spliton-with-generics[/url]