[英]entity framework not return refrence table data after insert new record to child table
我正在使用實體框架6。有兩個表,如parent and child
, parentid
上帶有外鍵。 我dded one new record in child table and savechanges()
了dded one new record in child table and savechanges()
完成了dded one new record in child table and savechanges()
。 當我執行此查詢時var childdata= _context.child.Where(p => p.childid == childid).FirstOrDefault();
然后它正確返回子表,但是當我使用childdata.parent
它顯示為null。 由於表之間存在外鍵,因此當我們獲得子表數據時,它應該返回父數據。
有三個項目。 它們是Repository, webapplication and webservice.
。 調用是跨存儲庫的。 因此,當我從Web服務調用時,它可以正常運行父數據,但在Web應用程序中卻無法正常工作。
使用Include()
方法包括父項:
childdata= _context.child.Include("parent").Where(p => p.childid == childid).FirstOrDefault();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.