2016-06-10 76 views
2

我正在使用實體框架6最新穩定版本與羅斯文數據庫。然後我寫下如下的查詢。即使我沒有包括客戶訂購。還包括實體OrderDetails有Order(這就像遞歸)。即使我沒有包含,OrderDetails的最終包含實體Product也有Category。奇怪的是,供應商是一個導航屬性,但它對於產品是空的。實體框架包含和選擇是gettind一些其他實體

加:惰性加載和ProxyCreationEnabled是假

var orders = Context.Orders 
      .Include(i => i.Order_Details) 
      .Include(i => i.Order_Details.Select(a => a.Product)) 
      .Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId) 
      .ToList(); 

Product property on Order

而且的OrderDetail的問題

Category and Supplier is so weird

我不能趕上這個是什麼?

+0

如果供應商爲空意味着數據將不在您的存儲庫中 –

+0

因爲我不想要供應商,以及我不想要類別。沒有包含查詢,因爲你看到 –

+0

那麼,你沒有'包括'供應商,我們不知道是否一切正常設置,以支持延遲加載供應商。可能不會。你必須顯示你的地圖,以便我們能夠對此進行任何說明。 –

回答

0

,你可以把一個選擇,如果你不想不想要的數據從table.you可以選擇匿名或使用視圖模型類做

var orders = Context.Orders 
      .Include(i => i.Order_Details) 
      .Include(i => i.Order_Details.Select(a => a.Product)) 
      .Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId) 
      .Select new 
      { 
       //here you can select the fields which all are you required 
      } 

  .Select new requireddatavm 
      { 
       //here you can select the fields which all are you required 
      } 

在方法的語法,用其他運營商:

.Where(i => i.EmployeeID == employeeId && i.CustomerID == customerId) 

,返回包含字段在內的整行