我在我的数据库中使用 EF-CORE 在 ASP.NET Core MVC 网站上工作。
我有一张Doc
桌子和一张Signature
桌子:
一个人Doc
可以有很多Signatures
一个Signature
只能上Doc
。
这是我的代码优先实体模型:
public class Doc
{
[Key]
public int DocID { get; set; }
[Required]
public int DocTypeID { get; set; }
[ForeignKey("DocTypeID")]
public virtual DocType DocType { get; set; }
[Required]
public int Version { get; set; }
[Required]
public Byte[] Data { get; set; }
[ForeignKey("DocID")]
public List<Signature> Signatures { get; set; }
}
签名
public class Signature
{
//FK ITPolicyVersion
[Key]
public int DocID { get; set; }
[ForeignKey("DocID")]
public virtual Doc Doc { get; set; }
//FK EmployeeID
[Key]
public int EmployeeID { get; set; }
[ForeignKey("EmployeeID")]
public virtual Employee Employee { get; set; }
[Required]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)]
[Display(Name = "Signature Date")]
public DateTime? SignatureDate { get; set; }
public String Value { get; set; }
}
但是当我使用这个请求时:
_applicationDBContext.Doc
.Include(d => d.DocType)
.Include(d => d.Signatures)
.OrderBy(d => d.DocType)
.ToList();
d.Signatures 始终为空,我不知道为什么。
这是我在 SQL 中尝试执行的操作:
SELECT * FROM Doc d
JOIN DocType dt ON dt.DocTypeID = d.DocTypeID
JOIN Signature s ON s.DocID = d.DocID
JOIN Employee e ON e.EmployeeID = s.EmployeeID
这在 SQL 中运行良好,但不适用于 LINQ
慕码人2483693
相关分类