2009-12-23 96 views
1

Linq to SQL有一些經驗我現在正在嘗試ADO實體框架。在Linq to SQL中,我將創建一個Linq to SQL類,拖動我的表來構建數據上下文。然後,我會實例化datacontext類並針對datacontext類中的某個屬性運行一些lambda。ADO實體框架幫助

現在,使用ADO實體框架添加實體數據模型類,然後將這些表添加到數據模型中。我的實體數據模型類現在有一堆ObjectQuery <>屬性,一個用於我添加的每個表。

現在我該如何處理這些屬性?我如何給他們打電話?任何人都有代碼示例?

回答

5

當然。我有a long presentation on this

作爲一個簡單的回答你的問題,這裏有一些你可以用ObjectQuery<T>屬性做的事情。

返回對象的列表:

IEnumerable<Customer> result = Context.Customers; 
return result; 

返回一個對象:

return Context.Customers.Where(c => c.Id == someId).First(); 

項目上表現模型:

return (from c in Customers 
     where c.Id == someId 
     select new CustomerPresentation 
     { 
      Id = c.Id, 
      Name = c.Name, 
      OrderCount = c.Orders.Count(), 
      PhoneNumbers = from p in c.PhoneNumbers 
          select new PhoneNumberPresentation 
          { 
           AreaCode = p.AreaCode, 
           // etc. 
          }, 
      // etc. 
     }).First();