Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net web api 在AutoMapper中从Asp.Net标识映射用户表_Asp.net Web Api_Asp.net Identity_Automapper - Fatal编程技术网

Asp.net web api 在AutoMapper中从Asp.Net标识映射用户表

Asp.net web api 在AutoMapper中从Asp.Net标识映射用户表,asp.net-web-api,asp.net-identity,automapper,Asp.net Web Api,Asp.net Identity,Automapper,在Asp.NETCore中,我重写了IdentityUser表以添加更多功能 public class Person : IdentityUser { public string Location {get; set; } public SellerType SellerType{get; set; } } public enum SellerType { PrivateSeller , Dea

在Asp.NETCore中,我重写了IdentityUser表以添加更多功能

public class Person : IdentityUser
    {
        public string Location {get; set; }
        public SellerType SellerType{get; set; }

    }
    public enum SellerType 
    {
        PrivateSeller , 
        Dealer
    }
我还有一个ViewModel类CredentialModel,我正在用AutoMapper与Person类链接

public class CredentialModel
  {
    public string UserName { get; set; }
    public string Password { get; set; }
    public string FirstName {get;set;}
    public string LastName {get; set; }
    public string Location {get; set; }
    public string SellerType{get; set; }
    public string[] SellerTypes {get; set; }
    public string PhoneNumber {get; set; }
  }
和AutoMapper Profile类

public class UserMapProfile : Profile
    {
        public UserMapProfile(){
          CreateMap<CarAdderUser, CredentialModel>()
             .ForMember(model=> model.SellerType , 
             opt=> opt.MapFrom(vm=>((SellerType)vm.SellerType).ToString()))
             .ForMember(model=> model.SellerTypes, opt=> opt.UseValue(Enum.GetNames(typeof(SellerType)).ToArray()))
                .ReverseMap();
        }
    }
就像这样,它扔给我一个404的邮递员

[HttpGet("getUser/{username}")]
     public  IActionResult GetUser(string username)
     {
         var user= _userManager.FindByNameAsync(username);
         return Ok(_mapper.Map<CredentialModel>(user));
     }

不知道该怎么办。。。不是汽车制造商专家解决了。。。问题是我忘了我只需要结果。。。 所以返回的是user.Result而不是user。。。
不知道其他的东西是什么。。。它们不是数据库中用户表中的列

您不应该使用
User.Result
。这将阻止调用线程。改用
async/await

 public async Task<IActionResult> GetUser(string username)
 {
     var user= await _userManager.FindByNameAsync(username);
     return Ok(_mapper.Map<CredentialModel>(user));
 }
public异步任务GetUser(字符串用户名)
{
var user=await\u userManager.FindByNameAsync(用户名);
返回Ok(_mapper.Map(用户));
}
 An unhandled exception has occurred: Missing type map configuration or unsupported mapping.

      Mapping types:
      Task`1 -> CredentialModel
 public async Task<IActionResult> GetUser(string username)
 {
     var user= await _userManager.FindByNameAsync(username);
     return Ok(_mapper.Map<CredentialModel>(user));
 }