は、ApplicationUser
基本クラスから継承された学生のクラス(ASP.NET同一性)があり、以下に示すように、それはStudentViewModel
と呼ばのViewModel
がある:なぜAutomapperベース・継承クラスのために働いていないMVCアプリケーションで
エンティティークラス:
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; }
}
のViewModel:
public class StudentViewModel
{
public int Id { get; set; }
public int? Number { get; set; }
//code omitted for brevity
}
私はコントローラでApplicationUser
へのマッピングStudentViewModel
によって学生を更新するために、次のメソッドを使用します。
[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
}
この方法を使用するとき、私はエラーが発生します。
The type arguments for method 'UserManagerExtensions.Update(UserManager, TUser)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
任意のアイデアへ修理する?
@BalagurunathanMarimuthuにそれを変更するかを持っていますか? –