0

ApplicationUserMVC アプリケーションには、基本クラス (ASP.NET Identity)から継承された Student クラスがあり、以下に示すようViewModelに呼び出されるクラスがあります。StudentViewModel

エンティティ クラス:

public class ApplicationUser : IdentityUser<int, ApplicationUserLogin,
                                     ApplicationUserRole, ApplicationUserClaim>, IUser<int>
{
    public string Name { get; set; }
    public string Surname { get; set; } 
    //code omitted for brevity
}

public class Student: ApplicationUser
{     
    public int? Number { get; set; }
}

ビューモデル:

public class StudentViewModel
{
    public int Id { get; set; }     
    public int? Number { get; set; }
    //code omitted for brevity
}

Controller にマッピングStudentViewModelして Student を更新するには、次のメソッドを使用します。ApplicationUser

[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult Update([Bind(Exclude = null)] StudentViewModel model)
{
    //Mapping StudentViewModel to ApplicationUser ::::::::::::::::
    var student = (Object)null;

    Mapper.Initialize(cfg =>
    {
        cfg.CreateMap<StudentViewModel, Student>()
            .ForMember(dest => dest.Id, opt => opt.Ignore())
            .ForAllOtherMembers(opts => opts.Ignore());
    });

    Mapper.AssertConfigurationIsValid();
    student = Mapper.Map<Student>(model);
    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    //Then I want to pass the mapped property to the UserManager's Update method:
    var result = UserManager.Update(student);

    //code omitted for brevity              
}

この方法を使用すると、次のエラーが発生します。

メソッド 'UserManagerExtensions.Update(UserManager, TUser)' の型引数は、使用法から推測できません。型引数を明示的に指定してみてください。

それを修正するアイデアはありますか?

4

1 に答える 1