隐藏API主体中的参数


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();
}

主体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声明它们。

有人给我小费吗?

对不起,我的英语不够用。

尝试这个

public async Task<ActionResult<IEnumerable<EmployeeDto>>> GetEmployees()
{
return await _context.Employees
.Select(i=> new EmployeeDto
{ 
employeeId=i.EmployeeId,
lastName=i.LastName,
firstName=i.FirstName,
adressInfo=i.Address
}
.ToListAsync();
}}

相关内容

  • 没有找到相关文章