这是相同问题的对应物(但使用 AutoMapper)。我使用ValueInjecter,如果有解决方案,我很感兴趣。
简化代码示例:
// get a list of viewModels for the grid.
// NOTE: sort parameter is flattened property of the model (e.g. "CustomerInvoiceAmount" -> "Customer.Invoice.Amount"
// QUESTION: how do I get original property path so I can pass it to my repository for use with Dynamic LINQ?
public HttpResponseMessage Get(string sort)
{
var models = _repo.GetAll(sort) // get a list of domain models
var dto = _mapper.MapToDto(models); // get a list of view models that are flattened via dto.InjectFrom<FlatLoopValueInjection>(models);
var response = new HttpResponseMessage();
response.CreateContent(vehicles);
return response;
}