简体   繁体   中英

Non-normalized tables on Entity Framework 6.1

I got a Many-to-Many relashionship tables but one of them is non-normalized, and i'm getting this error: The specified association foreign key columns 'FLS_FIL_ID' are invalid. The number of columns specified must match the number of primary key columns. The specified association foreign key columns 'FLS_FIL_ID' are invalid. The number of columns specified must match the number of primary key columns.

The relashionship that i'm trying to do is between File and FlowStep as you can see they are to ICollections, but i got no success.

[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; }
}

And the mapping that i did so far:

        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");
            }); 

MapLeftKey takes params string array as all the foreign key names. MapLeftKey method's signature is as follows.

public ManyToManyAssociationMappingConfiguration MapLeftKey(
    params string[] keyColumnNames
)

referenced from this msdn documentation.

try specifying all the keys in MapLeftKey method call as following:

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");
        }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM