我确实使用UOW和存储库以及所有pocos等来启动IOC(Ninject)。但是在我的“获取”问题之后我认为我会退后一步并快速进行POC工作
所以我正在做的每一件事我只想和这个“技巧”poco谈谈
private DataContext _db = new DataContext();
调用导致错误的方法
public List<Skill> GetAllSkills()
{
var query = (from s in _db.Skills
select s).ToList();
return query;
}
DbContext
public DbSet<Skill> Skills { get; set; }
自动生成的poco(ado.net向导)
public partial class Skill
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Skill()
{
InternSkills = new HashSet<InternSkill>();
Projects = new HashSet<Project>();
}
public int Skillid { get; set; }
[StringLength(50)]
public string SkillName { get; set; }
[StringLength(2500)]
public string SkillDesc { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<InternSkill> InternSkills { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Project> Projects { get; set; }
}
我的错误
{“无法确定类型'PublicHealth.Intern.DataAccess.Data.Entities.AssignmentTime'和'PublicHealth.Intern.DataAccess.Data.Entities.Assignment'之间关联的主要结尾。此主要结束必须使用关系流畅API或数据注释显式配置关联。“}
更新
我在Skill poco中看到了Project
的poco
public virtual ICollection<Project> Projects { get; set; }
Project poco的代码
public partial class Project
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Project()
{
Assignments = new HashSet<Assignment>();
ProjectInternTimes = new HashSet<ProjectInternTime>();
Skills = new HashSet<Skill>();
}
public int ProjectId { get; set; }
public int? StatusId { get; set; }
public int? OfficeId { get; set; }
[StringLength(100)]
public string ContactNameLast { get; set; }
[StringLength(100)]
public string ContactNameFirst { get; set; }
[StringLength(100)]
public string ContactEmail { get; set; }
[StringLength(25)]
public string ContactPhone { get; set; }
[StringLength(2500)]
public string ProjectName { get; set; }
[Column(TypeName = "text")]
public string ProjectDesc { get; set; }
public bool? IsDateSpecific { get; set; }
[Column(TypeName = "date")]
public DateTime? DateStart { get; set; }
[Column(TypeName = "date")]
public DateTime? DateEnd { get; set; }
public int? EstimatedWeeks { get; set; }
public DateTime? DateRequested { get; set; }
public int? JobTitleId { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Assignment> Assignments { get; set; }
public virtual JobTitle JobTitle { get; set; }
public virtual Office Office { get; set; }
public virtual Status Status { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<ProjectInternTime> ProjectInternTimes { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Skill> Skills { get; set; }
}
}