无法将DataProxies类型的对象强制转换为ICollection

时间:2015-12-12 02:30:30

标签: c# sql entity-framework asp.net-mvc-5

  

完整错误无法将'System.Data.Entity.DynamicProxies.ActionDirectory_7F5D2D03963A3C92299CAFAA12CCA26909F2F8597FD704BC77CDFD6F25A01E33'类型的对象强制转换为'System.Collections.Generic.ICollection`1 [FBT_GRASP.Models.ActionDirectory]'。

所以我正在使用一些遗留代码并正在实例化一个GrievanceStep。想要得到它......

GrievanceStep step = db.GrievanceSteps.SingleOrDefault(gs=> gs.GrievanceStepId == id);

所以,当我在调试器中停止它时,一切看起来都很好但是当我尝试访问一个ActionDirectory实体时,一切顺利,直到我尝试访问ActionDirectory.Directory。

我真的很难解读这些代码以及发生了什么。我几乎肯定这些网站设置错误,但我的大脑因为长时间盯着它们而受伤。任何帮助都表示赞赏:D < / p>

public class ActionDirectory
{
    public Guid ActionID { get; set; }
    [ForeignKey("ActionID")]
    public virtual Action Action { get; set; }
    public Guid DirectoryID { get; set; }
    [ForeignKey("DirectoryID")]
    public virtual Filesystem Directory { get; set; }
    public Guid GrievanceStepID { get; set; }
    [ForeignKey("GrievanceStepID")]
    public virtual GrievanceStep GrievanceStep { get; set; }
}

类试图获得directiores

public class GrievanceStep
{        
    [Column("GrievanceStepId")]
    public Guid GrievanceStepID { get; set; }
    public String Name { get; set; }
    public bool Completed { get; set; }
    public string CompletedOn { get; set; }
    public Guid? GrievanceID { get; set; }
    [ForeignKey("GrievanceID")]
    public virtual Grievance Grievance { get; set; }
    public bool IsNullStep { get; set; }
    public virtual ICollection<Action> Actions { get; set; }
    public virtual ICollection<GrievancePropertyField> Fields { get; set; }       
    public virtual ICollection<GrievanceStepProperty> DefaultProperties { get; set; }
    public virtual ICollection<GrievanceApprovers> GrievanceApprovers { get; set; }
    public virtual ICollection<DocumentGrievanceStep> GrievanceStepDocuments { get; set; }
    public virtual ICollection<DirectoryGrievanceStep> GrievanceStepDirectories { get; set; }
    [JsonIgnore]
    public virtual ICollection<ActionDocument> ActionDocuments { get; set; }
    [JsonIgnore]
    public virtual ICollection<ActionDirectory> ActionDirectories { get; set; }

}

这是FileSystems

public class Filesystem
{
    [Column("DirectoryID")]
    public Guid DirectoryID { get; set; }
    public HierarchyId hNode { get; set; }
    public string Name { get; set; }
    public bool Active { get; set; }
    public Guid CreatedByID { get; set; }
    [ForeignKey("CreatedByID")]
    [Required]
    public virtual User Creator { get; set; }
    [JsonIgnore]
    [ForeignKey("ActionID")]
    public virtual ICollection<ActionDirectory> ActionDirectories { get; set; }
    [JsonIgnore]
    public virtual ICollection<DirectoryGrievanceStep> DirectoryGrievanceSteps { get; set; }
}

0 个答案:

没有答案