我正在尝试使用以下 lambda 代码访问链接表字段:
DateTime dtStartDate = "1/1/2013"; // or some date
var jobs = db.jobs.Include(d => d.docs)
.Where(d => d.docs.duedate >= dtStartDate);
这是 SQL Server 中的表关系键:
jobs.JobID = docs.JobID
// Note: Check Existing Data = No.
那么,当我尝试在上面的第一行和第二行代码中执行以下操作时,为什么上面的代码不起作用:
// errors here
// .duedate can't be found through the .Include() table, docs
d.docs.duedate
错误说:
'System.Collections.Generic.ICollection' 不包含'duedate' 的定义,并且找不到接受'System.Collections.Generic.ICollection' 类型的第一个参数的扩展方法'duedate'(您是否缺少 using 指令还是汇编参考?)
实体框架生成的类代码:
public partial class jobs
{
public jobs()
{
this.docs = new HashSet<docs>();
}
public int JobID { get; set; }
public virtual ICollection<docs> docs { get; set; }
}
public partial class docs
{
public int DocumentID { get; set; }
public Nullable<int> JobID { get; set; }
public Nullable<System.DateTime> duedate { get; set; }
public virtual jobs jobs { get; set; }
}
我已经更新了 Visual Studio 中的模型以匹配数据库,但这仍然不起作用。知道为什么吗?非常感谢您的帮助。