本帖最后由 qizbigbird 于 2012-04-01 15:12:12 编辑 原错误信息:
Unable to determine the principal end of an association between the types 'ResearchProjectManagement.Models.DProject' and 'ResearchProjectManagement.Models.ProjectBudget'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
public class ProjectsinForschung
{
[Key]
public Guid ID { get; set; }
public Guid ProjectID { get; set; }
public DateTime Date { get; set; }
public string Comment { get; set; }
public virtual Project project { get; set; }
}
public class Project
{
[Key]
[ForeignKey("projectinforschung")]
public Guid ProjectID { get; set; }
public DateTime CreateDate { get; set; }
public DateTime FinishDate { get; set; }
public DateTime CutOffDate { get; set; }
public string Comment { get; set; }
public virtual ProjectsinForschung projectinforschung { get; set; }
}
public class ProjectsinForschung
{
[Key]
public Guid ID { get; set; }
public Guid ProjectID { get; set; }
public DateTime Date { get; set; }
public string Comment { get; set; }
public virtual Project project { get; set; }
}
取值代码:
List<ProjectsInDepartment> datesource = db.prosindeps.ToList();
datesource依次展开到ProjectsinForschung类时,取到null
高手指点!
------解决方案--------------------------------------------------------
你确定大小写无关?
------解决方案--------------------------------------------------------
回一楼:ForeignKey内参数,小写是对应变量名
已找到原因,ProjectID.ProjectID竟然对应到了ProjectsinForschung.ID,而不是,ProjectsinForschung.ProjectID,把ProjectsinForschung的主键设为ProjectID就行了。
不过,有没方法直接让两个ProjectID相关联?
------解决方案--------------------------------------------------------