我定义了以下类
文档类型
public class DocumentType
{
[DataMember]
[Key]
[ScaffoldColumn(false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[MaxLength(100, ErrorMessage = "The field Name must be maximum length of '100'.")]
public string Name { get; set; }
[MaxLength(200, ErrorMessage = "The field Description must be maximum length of '200'.")]
public string Description { get; set; }
[Required]
[MaxLength(30, ErrorMessage = "The field Category must be maximum length of '30'.")]
[Display(Name = "Category")]
public string CategoryName { get; set; }
[ScaffoldColumn(false)]
public bool IsDeleted { get; set; }
public virtual List<DocumentApplicability> DocumentApplicabilities { get; set; }
public virtual List<DocumentField> DocumentFields { get; set; }
}
文档类型字段
public class DocumentField
{
public int DocumentTypeID { get; set; }
[ForeignKey("DocumentTypeID")]
public DocumentType DocumentType { get; set; }
[DataMember]
[Key]
[ScaffoldColumn(false)]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required]
[MaxLength(30, ErrorMessage = "The field Name must be maximum length of '30'.")]
public string Name { get; set; }
[MaxLength(150, ErrorMessage = "The field Description must be maximum length of '150'.")]
public string Description { get; set; }
}
我从未看到填充过的文档字段。 Sql server告诉我db中有记录,但是当我在调用下面的函数后尝试使用此信息时,对于已记录的字段,我总是会得到null。
public static void GetDocumentTypes()
{
ef.DataContext d = new ef.DataContext();
var qry = (from adoctype in d.DocumentType select adoctype);
qry.Include("DocumentFields");
var q = qry.ToList();
Debug.WriteLine("done");
}
有人可以帮忙吗