[英]Using id from one table to read value from another table using Linq in sub query
嗨,我有以下玲查詢
var lst=(from p in db.business
where p.id == id
select new pO
{
pName = p.name,
newStructure = p.p_disc.Select(x=>
new newStructure
{
post_date=x.post_date,
posted_by_id=x.person.last_name.Where(x.posted_by_id==x.person.p_id)
})
});
newStructure類為
public class newStructureProject
{
public int posted_by_id { get; set; }
public System.DateTime post_date { get; set; }
public person person { get; set; }
}
在下面的查詢行中,我嘗試在newStructure中使用posted_by_id從人員表中讀取姓氏和名字。
posted_by_id=x.person.last_name.Where(x.posted_by_id==x.person.p_id)
我收到intelisense錯誤“字符串不包含指向何處的定義.....。請讓我知道如何在查詢中使用它來使用posted_by_id讀取人員表中的姓氏和名字,它們具有外鍵關系。謝謝
試試這個姓氏。
posted_by_id=x.person.Where(x=>x.posted_by_id==x.person.p_id).Select(x=>x.last_name).FirstOrDefault()
您需要首先在對象上應用where子句,然后選擇所需的屬性值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.