[英]Automapper with c#
I am trying to increase performance of my api with automapper. 我正在尝试通过自动映射器来提高我的api的性能。 I have created the destination DTO and i have a source mnodel already.
我已经创建了目标DTO,并且已经有一个源mnodel。 I've also created the mapping but when i map this error.
我还创建了映射,但是当我映射此错误时。
The type arguments for method 'Enumerable.Select<TSource, TResult>
(IEnumerable<TSource>, Func<TSource, TResult>)' cannot be inferred from the
usage. Try specifying the type arguments explicitly.
See code sample below 请参阅下面的代码示例
[Route("StaffInfo/{*job_title}")]
public IHttpActionResult GetStaffInfoByTitle(string job_title)
{
var rStructure = _context.employeeinfo.Where(e => e.jobtitle.Contains(job_title)).ToList()
.Select(Mapper.Map<employeeinfo, employeeinfoDto>);
if (rStructure == null)
{
return NotFound();
}
return Ok(rStructure);
}
DTO model DTO模型
public class employeeinfoDto
{
public string employee_number { get; set; }
public string name { get; set; }
public string companyname { get; set; }
public int employee_id { get; set; }
public Byte? linemanager { get; set; }
}
Domian model 多米安模型
public class employeeinfo
{
public string employee_number { get; set; }
public string name { get; set; }
public string companyname { get; set; }
public int employee_id { get; set; }
public Byte? linemanager { get; set; }
}
Mapping profile 映射资料
Mapper.CreateMap<employeeinfo, employeeinfoDto>();
You can use the Queryable Extensions like so: 您可以像这样使用Queryable Extensions:
var rStructure = _context.employeeinfo.Where(e => e.jobtitle.Contains(job_title))
.ProjectTo<employeeinfoDto>().ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.