我有一個存儲庫:選擇正確的集合/列表爲我的倉庫
public ObservableCollection<ProjectExpenseBO> GetProjectExpenses()
{
//Get by query
IQueryable<ProjectExpenseBO> projectExpenseQuery =
from p in _service.project_expense
from e in _service.vw_employee
where p.employee_id == e.employee_id
select new ProjectExpenseBO()
{
ProjectExpenseID = p.project_expense_id
, EmployeeID = p.employee_id
, ProjectNumber = p.project_number
, PurchaseTypeID = p.purchase_type_id
, BuyerEmployeeID = p.buyer_employee_id
, PurchaseOrderNumber = p.purchase_order_number
, DeliveryDate = p.delivery_date
, EmployeeName = e.first_name + " " + e.last_name
};
ObservableCollection<ProjectExpenseBO> projectExpenseCollection = new ObservableCollection<ProjectExpenseBO>(projectExpenseQuery);
return projectExpenseCollection;
}
我想知道如果這是更好地回報從我的倉庫一個IList或IEnumerable的(而不是一個ObservableCollection)因爲我的視圖模型可能最終將其放入ObservableCollection或List中,具體取決於我的需要。例如,我可能會將數據從上述存儲庫返回到只讀數據網格或下拉列表,或者我可能需要可編輯數據網格中的相同數據。
我在想(可能是錯誤),我希望我的存儲庫返回準系統列表,然後將其轉換爲我在視圖模型中需要的套件。我的想法是否正確?這是我在想什麼:
public IEnumerable<ProjectExpenseBO> GetProjectExpenses()
{
//Get by query
IQueryable<ProjectExpenseBO> projectExpenseQuery =
from p in _service.project_expense
from e in _service.vw_employee
where p.employee_id == e.employee_id
select new ProjectExpenseBO()
{
ProjectExpenseID = p.project_expense_id
, EmployeeID = p.employee_id
, ProjectNumber = p.project_number
, PurchaseTypeID = p.purchase_type_id
, BuyerEmployeeID = p.buyer_employee_id
, PurchaseOrderNumber = p.purchase_order_number
, DeliveryDate = p.delivery_date
, EmployeeName = e.first_name + " " + e.last_name
};
return projectExpenseQuery;
}
謝謝。
謝謝!我將不得不看看延遲執行會如何影響我的應用程序。我發現這個線程,需要更好地閱讀: http://stackoverflow.com/questions/1168944/how-to-tell-if-an-ienumerablet-is-subject-to-deferred-execution – steveareeno 2010-07-08 21:24:04