【发布时间】:2013-06-11 18:27:37
【问题描述】:
我正在尝试使用以下 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 指令还是程序集引用?)
Entity Framework 生成的类代码:
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 中更新了模型以匹配数据库,但这仍然无法正常工作。知道为什么吗?非常感谢您的帮助。
【问题讨论】:
标签: c# sql-server asp.net-mvc entity-framework