EF4 Unknown Column In Field List

孤街浪徒 提交于 2019-12-02 07:21:48

I think this issue is because you havent configured your navigation property to use the FK field you have defined.

You should use:

modelBuilder.Entity<Completed>().HasRequired(e => e.OldStep ).WithMany().HasForeignKey(e => e.OldStepId )

or try:

public class Completed
{
    [Key]
    public int CompletedId { get; set; }

    public int OldStepId { get; set; }
    public int NewStepId { get; set; }
    public string Name { get; set; }
        
    [ForeignKey("OldStepId")]
    public virtual Step OldStep { get; set; }

    [ForeignKey("NewStepId")]
    public virtual Step NewStep { get; set; }
}

public class Step
{
    [Key]
    public int StepId { get; set; }

    public string Name { get; set; }
    public string Description { get; set; }
}

refer to http://xhalent.wordpress.com/2011/01/21/configuring-entity-framework-4-codefirst/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!