2016-10-03 7 views
0

オーバーライドボイドParseEntityに追加し、次のエラーメッセージを取得しようとすると:ASP.NET IDのApplicationUserをオーバーライドすることは可能ですか?

重大度コード説明プロジェクトファイルの行の抑制状態 エラーCS0115「ApplicationUser.ParseEntity(REF ApplicationUser)」:上書きすることが分かっていない適切な方法を... 。

public override void ParseEntity(ref ApplicationUser entity) 
    { 
     entity.Email = Email; 
     entity.UserName = Email; 
     entity.FirstName = FirstName; 
     entity.LastName = LastName; 
     entity.UserTypeID = UserTypeID; 
     entity.ModifiedDate = DateTime.Now; 
     entity.ModifiedBy = Id; 
    } 

を私IdentityModel.csに:\モデル\ IdentityModels.cs 47アクティブ

は、私が追加しようとしています。次のようにApplicaionUserに見える:

public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> 
    { 
     public ApplicationUser() 
     { 
      this.Id = Guid.NewGuid().ToString(); 
      // Add any custom User properties/code here 
     } 
     [Display(Name = "First Name")] 
     [Required] 
     public string FirstName { get; set; } 
     [Display(Name = "Last Name")] 
     [Required] 
     public string LastName { get; set; } 
     [Display(Name = "Guarantee Limit")] 
     public Nullable<double> GuaranteeLimit { get; set; } 
     [Display(Name = "User Type")] 
     public int UserTypeID { get; set; } 
     [Display(Name = "Terms And Conditions Version")] 
     public string TermsAndConditionsVersion { get; set; } 
     [Display(Name = "Last Terms And Conditions Date")] 
     public DateTime ? LastTermsAndConditionsDate { get; set; } 
     [Display(Name = "Last Login Date And Time")] 
     public DateTime ? LastLoginDateTime { get; set; } 
     [Display(Name = "Created Date")] 
     public DateTime CreatedDate { get; set; } 
     [Display(Name = "Modified Date")] 
     public DateTime ? ModifiedDate { get; set; } 
     [Display(Name = "Modified By")] 
     public string ModifiedBy { get; set; } 

/////////////////I want to add the override here///////////////// 

     public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager) 
     { 
      // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
      var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 
      // Add custom user claims here 
      return userIdentity; 
     } 
    } 

は、私がここにオーバーライドを追加することができAMまたは私は何かが足りないのですか?私はいくつかの投稿として見て、System.Web.Mvcを使用して追加することをお勧めしましたが、これは同じエラーメッセージでは違いはありません。

+1

「ParseEntity」メソッドはどこにもありません。 'override'を削除して、それを使用したい場合は問題ありません。 – trailmax

答えて

1

お客様のApplicationUserはです。 IdentityUserインターフェイスを実装しています。インタフェースにはオーバーライドするものはありません。あなたのApplicationUserクラスはで、をにオーバーライドするには、に仮想または抽象メソッドとしてParseEntityを持つ別のクラスから継承する必要があります。

+2

' IdentityUser'はクラスであり、インターフェースではありません(https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity)。 entityframework.identityuser(v = 1010).aspx)、答えの最初の部分が間違っています。 – kiziu

+0

申し訳ありませんが、IdentityUserはインターフェイスではありませんでした。どのクラスがParseEntityを呼び出すのですか?そこから、そのクラスがインターフェイスで動作するかどうか、またはクラスでなければならないかどうかを、そのクラスが期待しているはずです。うまくいけばインターフェイスを作成し、それをApplicationUserに追加するだけで済みます。そうでない場合は、IdentityUserが実装するすべてのインタフェースをApplicationUserに実装させて、すべてのインタフェースを実装する必要があります。 – ManOVision

+1

入力いただきありがとうございます。私は、オーバーライドを使用していたプロジェクトの例に従っていましたが、オーバーライドする必要がないので、それを削除し、ParseEntity(ref ApplicationUserエンティティ)を完全に無効にしてください。あなたの助けを借りてくれてありがとう。 –

関連する問題