【发布时间】:2021-09-28 22:24:55
【问题描述】:
public partial class Employee
{
public int EmployeeId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Title { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
}
dto类
{
public int EmployeeId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Title { get; set; }
public string infoAdress{get; set;}
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
}
获取方法
public async Task<ActionResult<IEnumerable<EmployeeDto>>> GetEmployees()
{
return await _context.Employees
.ProjectTo<EmployeeDto>(_imapper.ConfigurationProvider).ToListAsync();
}
body api 是:
{
"employeeId": 0,
"lastName": "string",
"firstName": "string",
"adressInfo": "string",
"address": "string",
"city": "string",
"region": "string",
"postalCode": "string",
"country": "string"
}
我希望该方法只返回这些数据:
{
"employeeId": 0,
"lastName": "string",
"firstName": "string",
"adressInfo": "string",
}
在 adressInfo 中,我将字符串 Address、City、Region、Postal Code 和 Country 连接起来,单个字符串,我需要为 post 方法的 reverseMap 声明它们。
有人给我小费吗?
对不起,我的英语还不够。
【问题讨论】:
-
这能回答你的问题吗? Hide properties from web api response