我想給繼承類提供一個where子句給我的查詢的機會。這可能嗎?IQueryable where子句被繼承類重寫
protected IQueryable<EntityResult> GetEntities(ETBDataContext pContext)
{
return from e in pContext.Entities
where e.StatusCode == "Published"
//is there a way to add a dynamic where clause here?
//I would like to ask the inherited class for it's input:
&& e.OtherColumn == "OtherValue" // <-- like GetWhere(e)?
//without having to select the column
orderby e.PublishDate descending
select new EntityResult
{
Name = e.Name,
Link = e.Link
};
}
先謝謝了!!!!!!!!!!
非常感謝。此代碼第一次編譯和工作。只有一個問題:所有這些仍然是在數據源上執行還是將其加載到內存中然後進行過濾? –
有趣的是,我從來沒有想過在第一種方法中分裂它。 –
只要您使用'IQueryable',就不會在數據庫中執行任何操作。只有在調用.ToList()或類似的函數時,或者在結果上開始執行foreach纔會實際執行鍼對數據庫的查詢。 – jeroenh