我有以下代碼,我正在使用EF 4.1和Unit of Work中的存儲庫模式。 但是,因爲我不太瞭解表達式和謂詞如何工作,請詢問以下內容:使用謂詞來查找所有行?
使用下面的代碼,是否有更好的方法來查找所有行?
public ActionResult Index()
{
var positions = unitOfWork.PositionRepository
.Find(p => p.PositionID != null);
return View(positions.ToList());
}
我根據我的UnitOfWork和庫從這裏 http://www.asp.net/entity-framework/tutorials/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
我嘗試這樣做:
public virtual List<TEntity> GetAll()
{
return context.Set<TEntity>.ToList();
}
'Set'是一種方法... –
笑。 thx :) :) :) –