2015-04-06 147 views
0

我得到了許多對許多relashionship表,但其中一人是不正常的,這我得到這個錯誤:The specified association foreign key columns 'FLS_FIL_ID' are invalid. The number of columns specified must match the number of primary key columns.非規範化表6.1

的relashionship,我試圖要做的是在File和FlowStep之間,你可以看到它們是ICollections,但我沒有成功。

[Table("Controller.TB_FlowStep")] 
    public partial class FlowStep : Entity<int> 
    { 
     [StringLength(8)] 
     public string FLS_FLO_ID { get; set; } 

     [Key] 
     [Column(Order = 0)] 
     [DatabaseGenerated(DatabaseGeneratedOption.None)] 
     public int FLS_FIL_ID { get; set; } 

     [Key] 
     [Column(Order = 1)] 
     [DatabaseGenerated(DatabaseGeneratedOption.None)] 
     public int FLS_STE_ID { get; set; } 

     public DateTime FLS_TimeStamp { get; set; } 

     [Key] 
     [Column(Order = 2)] 
     [DatabaseGenerated(DatabaseGeneratedOption.None)] 
     public int FLS_STS_ID { get; set; } 

     public virtual Flow Flow { get; set; } 

     public virtual Step Step { get; set; } 

     public virtual StepStatus StepStatus { get; set; } 

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

[Table("Controller.TB_File")] 
public partial class File 
{ 
    [Key] 
    public int FIL_Id { get; set; } 

    public DateTime FIL_Date { get; set; } 

    [Required] 
    [StringLength(1)] 
    public string FIL_Type { get; set; } 

    [Column(TypeName = "ntext")] 
    [Required] 
    public string FIL_Body { get; set; } 

    [StringLength(20)] 
    public string FIL_SQC { get; set; } 

    [StringLength(10)] 
    public string FIL_ENV { get; set; } 

    public ICollection<FlowStep> FlowStep { get; set; } 
} 

而且我確實到目前爲止映射:

 modelBuilder.Entity<FlowStep>() 
      .HasMany(e => e.File) 
      .WithMany(e => e.FlowStep) 
      .Map(e => 
      { 
       e.MapLeftKey("FLS_FIL_ID"); 
       e.MapRightKey("FIL_ID"); 
       e.ToTable("TB_FlowStep"); 
      }); 
+0

爲什麼你需要三個'Key's在頭等艙?他們也是外國人嗎? – renakre 2015-04-06 13:16:34

回答

0

MapLeftKey需要PARAMS字符串數組因爲所有的外鍵的名稱。 MapLeftKey方法的簽名如下。

public ManyToManyAssociationMappingConfiguration MapLeftKey(
    params string[] keyColumnNames 
) 

引用自this msdn文檔。

嘗試指定在MapLeftKey方法調用所有的按鍵如下:

modelBuilder.Entity<FlowStep>() 
     .HasMany(e => e.File) 
     .WithMany(e => e.FlowStep) 
     .Map(e => 
     { 
      e.MapLeftKey("FLS_FIL_ID","FLS_STE_ID","FLS_STS_ID"); 
      e.MapRightKey("FIL_ID"); 
      e.ToTable("TB_FlowStep"); 
     }); 
+0

現在我收到了這個錯誤:在模型生成過程中檢測到一個或多個驗證錯誤:FlowStepFile:Name:已經定義了模式爲'Controller'和表'TB_FlowStep'的EntitySet'FlowStepFile'。每個EntitySet必須引用一個唯一的模式和表。 – 2015-04-06 13:22:54

+0

@Vinícius您可能需要運行遷移或刪除並重新創建數據庫。 – 2015-04-06 13:24:14

+0

但我沒有使用遷移,我不能刪除我的數據庫 – 2015-04-06 13:26:48