实体框架无效列问题

时间:2016-02-10 15:34:39

标签: entity-framework ef-code-first

从Entity Framework中选择时,它会生成如下所示的SQL。我没有在项目的任何地方提到过下面突出显示的列。这些列正在生成无效的列异常。

请帮我解决这个问题。

由于 Iliyas

{SELECT 
    [Extent1].[Question_Qualifying_Skills_Map_Key] AS [Question_Qualifying_Skills_Map_Key], 
    [Extent1].[Question_Key] AS [Question_Key], 
    [Extent1].[Skill_Level_Key] AS [Skill_Level_Key], 
    [Extent1].[Skill_Code] AS [Skill_Code], 
    [Extent1].[Level_number] AS [Level_number], 
    [Extent1].[Record_Start_Date] AS [Record_Start_Date], 
    [Extent1].[Record_End_Date] AS [Record_End_Date], 
    [Extent1].[Record_Created_Date] AS [Record_Created_Date], 
    [Extent1].[Record_Modified_Date] AS [Record_Modified_Date], 
    [Extent1].[Record_Status_Key] AS [Record_Status_Key], 
    [Extent1].[Record_Modified_By] AS [Record_Modified_By], 
    [Extent1].[Record_Created_By] AS [Record_Created_By], 
    [Extent1].[Phoenix_Users_T_User_Key] AS [Phoenix_Users_T_User_Key], 
    [Extent1].[Phoenix_Users_T1_User_Key] AS [Phoenix_Users_T1_User_Key], 

***[Extent1].[Phoenix_Users_T_User_Key1] AS [Phoenix_Users_T_User_Key1], 
    [Extent1].[Phoenix_Users_T_User_Key2] AS [Phoenix_Users_T_User_Key2]***

FROM [dbo].[Question_Qualifying_Skills_Map_T] AS [Extent1]

这些是我的实体类:

public partial class Question_Qualifying_Skills_Map_T : BaseVo<Int64>
{
    [Key]
    public int Question_Qualifying_Skills_Map_Key { get; set; }
    public int Question_Key { get; set; }
    public int Skill_Level_Key { get; set; }
    public string Skill_Code { get; set; }
    public int Level_number { get; set; }
    public Nullable<System.DateTime> Record_Start_Date { get; set; }
    public Nullable<System.DateTime> Record_End_Date { get; set; }
    public Nullable<System.DateTime> Record_Created_Date { get; set; }
    public Nullable<System.DateTime> Record_Modified_Date { get; set; }
    public int Record_Status_Key { get; set; }
    public int Record_Modified_By { get; set; }
    public int Record_Created_By { get; set; }
    public virtual Phoenix_Users_T Phoenix_Users_T { get; set; }
    public virtual Phoenix_Users_T Phoenix_Users_T1 { get; set; }
    public virtual Questions_T Questions_T { get; set; }
    public virtual Record_Status_T Record_Status_T { get; set; }
    public virtual Skill_Levels_T Skill_Levels_T { get; set; }
}

public class Question_Qualifying_Skills_Map_TMap :  EntityTypeConfiguration<Question_Qualifying_Skills_Map_T>
{
    public Question_Qualifying_Skills_Map_TMap()
    {
        // Primary Key
        this.HasKey(t => t.Question_Qualifying_Skills_Map_Key);

        // Properties
        this.Property(t => t.Question_Qualifying_Skills_Map_Key)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        this.Property(t => t.Skill_Code)
            .IsRequired()
            .HasMaxLength(64);

        // Table & Column Mappings
        this.ToTable("Question_Qualifying_Skills_Map_T");
        this.Property(t => t.Question_Qualifying_Skills_Map_Key).HasColumnName("Question_Qualifying_Skills_Map_Key");
        this.Property(t => t.Question_Key).HasColumnName("Question_Key");
        this.Property(t => t.Skill_Level_Key).HasColumnName("Skill_Level_Key");
        this.Property(t => t.Skill_Code).HasColumnName("Skill_Code");
        this.Property(t => t.Level_number).HasColumnName("Level_number");
        this.Property(t => t.Record_Start_Date).HasColumnName("Record_Start_Date");
        this.Property(t => t.Record_End_Date).HasColumnName("Record_End_Date");
        this.Property(t => t.Record_Created_Date).HasColumnName("Record_Created_Date");
        this.Property(t => t.Record_Modified_Date).HasColumnName("Record_Modified_Date");
        this.Property(t => t.Record_Status_Key).HasColumnName("Record_Status_Key");
        this.Property(t => t.Record_Modified_By).HasColumnName("Record_Modified_By");
        this.Property(t => t.Record_Created_By).HasColumnName("Record_Created_By");

        // Relationships
        this.HasRequired(t => t.Phoenix_Users_T)
            .WithMany(t => t.Question_Qualifying_Skills_Map_T)
            .HasForeignKey(d => d.Record_Modified_By);
        this.HasRequired(t => t.Phoenix_Users_T1)
            .WithMany(t => t.Question_Qualifying_Skills_Map_T1)
            .HasForeignKey(d => d.Record_Created_By);
        this.HasRequired(t => t.Questions_T)
            .WithMany(t => t.Question_Qualifying_Skills_Map_T)
            .HasForeignKey(d => d.Question_Key);
        this.HasRequired(t => t.Record_Status_T)
            .WithMany(t => t.Question_Qualifying_Skills_Map_T)
            .HasForeignKey(d => d.Record_Status_Key);
        this.HasRequired(t => t.Skill_Levels_T)
            .WithMany(t => t.Question_Qualifying_Skills_Map_T)
            .HasForeignKey(d => d.Skill_Level_Key);

    }
}
public partial class Phoenix_Users_T : BaseVo<Int64>
{
    public Phoenix_Users_T()
    {
        this.Question_Qualifying_Skills_Map_T = new List<Question_Qualifying_Skills_Map_T>();
        this.Question_Qualifying_Skills_Map_T1 = new List<Question_Qualifying_Skills_Map_T>();
    }

    public int User_Key { get; set; }
    public string User_Id { get; set; }
    public string User_First_Name { get; set; }
    public string User_Email { get; set; }
    public Nullable<int> MRALG_Map_Key { get; set; }
    public Nullable<System.DateTime> Record_Start_Date { get; set; }
    public Nullable<System.DateTime> Record_End_Date { get; set; }
    public Nullable<System.DateTime> Record_Created_Date { get; set; }
    public Nullable<System.DateTime> Record_Modified_Date { get; set; }
    public Nullable<int> User_Status_Key { get; set; }
    public string User_Last_Name { get; set; }
    public string User_Type { get; set; }
    public Nullable<System.DateTime> Last_Phoenix_Access_Date { get; set; }
    public string Reason { get; set; }
    public virtual ICollection<Question_Qualifying_Skills_Map_T> Question_Qualifying_Skills_Map_T { get; set; }
    public virtual ICollection<Question_Qualifying_Skills_Map_T> Question_Qualifying_Skills_Map_T1 { get; set; }
}
public class Phoenix_Users_TMap : EntityTypeConfiguration<Phoenix_Users_T>
{
    public Phoenix_Users_TMap()
    {
        // Primary Key
        this.HasKey(t => t.User_Key);

        // Properties
        this.Property(t => t.User_Key)
            .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

        this.Property(t => t.User_Id)
            .HasMaxLength(64);

        this.Property(t => t.User_First_Name)
            .IsRequired()
            .HasMaxLength(512);

        this.Property(t => t.User_Email)
            .IsRequired()
            .HasMaxLength(128);

        this.Property(t => t.User_Last_Name)
            .IsRequired()
            .HasMaxLength(512);

        this.Property(t => t.User_Type)
            .IsRequired()
            .HasMaxLength(20);

        this.Property(t => t.Reason)
            .HasMaxLength(1024);

        // Table & Column Mappings
        this.ToTable("Phoenix_Users_T");
        this.Property(t => t.User_Key).HasColumnName("User_Key");
        this.Property(t => t.User_Id).HasColumnName("User_Id");
        this.Property(t => t.User_First_Name).HasColumnName("User_First_Name");
        this.Property(t => t.User_Email).HasColumnName("User_Email");
        this.Property(t => t.MRALG_Map_Key).HasColumnName("MRALG_Map_Key");
        this.Property(t => t.Record_Start_Date).HasColumnName("Record_Start_Date");
        this.Property(t => t.Record_End_Date).HasColumnName("Record_End_Date");
        this.Property(t => t.Record_Created_Date).HasColumnName("Record_Created_Date");
        this.Property(t => t.Record_Modified_Date).HasColumnName("Record_Modified_Date");
        this.Property(t => t.User_Status_Key).HasColumnName("User_Status_Key");
        this.Property(t => t.User_Last_Name).HasColumnName("User_Last_Name");
        this.Property(t => t.User_Type).HasColumnName("User_Type");
        this.Property(t => t.Last_Phoenix_Access_Date).HasColumnName("Last_Phoenix_Access_Date");
        this.Property(t => t.Reason).HasColumnName("Reason");

        // Relationships
        this.HasOptional(t => t.MRALG_Map_T2)
            .WithMany(t => t.Phoenix_Users_T2)
            .HasForeignKey(d => d.MRALG_Map_Key);
        this.HasOptional(t => t.User_Status_T)
            .WithMany(t => t.Phoenix_Users_T)
            .HasForeignKey(d => d.User_Status_Key);

    }
}

0 个答案:

没有答案