客戶有很多ReservationRequests,ReservationRequest只有一個Customer。Linq with Entity Framework渴望加載
比方說,我找回像這樣
var c = dataContext.ReservationRequestSet.FirstOrDefault(i => i.id == RequestId);
我ReservationRequest我讓我的ReservationRequest沒有問題,但是當我做這樣的事情。
if (c != null)
{
int id = c.Customers.id;
我得到一個
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 75: if (c != null)
Line 76: {
Line 77: int id = c.Customers.id;
我有EF經驗非常少,但這種類型的東西NHibernate的工作沒有問題,我失去了一個環境某處EF?
感謝 吉姆
您使用的是哪個版本的實體框架?最新支持延遲加載,就像你期望的那樣,否則你必須編寫一些額外的代碼。 – 2010-11-01 19:34:37
有沒有簡單的方法來檢查? – jim 2010-11-02 03:24:11
我建議您在「客戶」中更改ReservationRequestSet「客戶」的導航屬性。它更可變。 – 2010-11-11 11:38:05