1
我使用下面的拉姆達代碼試圖訪問鏈接表中的字段:如何使用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'的定義,也沒有找到擴展方法'duedate'接受類型爲「System.Collections.Generic.ICollection」的第一個參數?由實體框架生成缺少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相匹配的數據庫模型,但仍這是行不通的。任何想法爲什麼?非常感謝您的幫助。
太棒了,謝謝!很好的解釋和例子! – ForeverLearningAndCoding