2017-01-09 4 views
1

をApplicationUser_Id。C#Entity Frameworkの6のMySQL - 挿入時に参照される未知の列には、私は、MySQLとEntity Frameworkの6を使用しています

public class AppSession 
{ 
    [Key] 
    public int Id { get; set; } 

    [MaxLength(36)] 
    public string SesId { get; set; } 

    [ForeignKey("User")] 
    public string UserId { get; set; } 

    public DateTime CreatedOn { get; set; } 

    public virtual ApplicationUser User { get; set; } 

    public virtual ICollection<AppSessionBreakdown> Breakdown { get; set; } 
} 

public class AppSessionBreakdown 
{ 
    [Key] 
    public int Id { get; set; } 

    [ForeignKey("AppSession")] 
    public int ASId { get; set; } 

    public string FileName { get; set; } 

    public virtual AppSession AppSession { get; set; } 
} 
挿入するための

私のC#コードは次のとおりです:いくつかの理由から

var breakdown = new AppSessionBreakdown { ASId = snapSession.Id, FileName = fileName }; 
repositoryAppSessionsBreakdown.Insert(breakdown); 
repositoryAppSessionsBreakdown.Save(); 

、私は生成されたSQLをチェックしたときに、EF6はどこにも指定されていない余分な列を追加してここに私のモデルの2は、

INSERT INTO `AppSessionBreakdowns`(`ASId`, FileName`, `ApplicationUser_Id`) VALUES (1, @gp1, NULL); 

私はAppSessionBreakdownモデルにApplicationUser列を追加する場合、それが作業を行いますが、私がPRに何を行うことができます。INSERT文は、このようなものです(ApplicationUser_Id)私はこれをちょうどうまく動作させるために無駄な列を追加したくありません。

ApplicationUserモデル:

public class ApplicationUser : IdentityUser 
{ 
    [Display(Name = "First Name")] 
    public string FirstName { get; set; } 

    [Display(Name = "Surname")] 
    public string LastName { get; set; } 

    public bool Activated { get; set; } 

    [DisplayFormat(DataFormatString = "({0:dd MMM yyyy})")] 
    [Display(Name = "Activated On")] 
    public DateTime? ActivatedOn { get; set; } 

    [DisplayFormat(DataFormatString = "({0:dd MMM yyyy})")] 
    [Display(Name = "Last Logged In")] 
    public DateTime? LastLoggedIn { get; set; } 

    public int ContractorId { get; set; } 

    public bool TestAccount { get; set; } 

    public virtual ICollection<TapInSite> TapInSite { get; set; } 

    public virtual ICollection<TapInLog> TapInLog { get; set; } 

    public virtual ICollection<AppSession> SnapAppSessions { get; set; } 

    public virtual ICollection<AppSessionBreakdown> SnapAppSessionsBreakdown { get; set; } 

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> 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; 
    } 
} 
+0

あなたも、 'ApplicationUser'・テーブル用のコードを提供していただけますか? –

+0

ApplicationUserありがとうございました。 – user984314

+1

あなたは、 – matcheek

答えて

0

はコメントで述べたように、これを引き起こしたApplicationUserクラスの列を含めました。

enter image description here

をそして、その結果は次のようになります:

関連する問題