내 Entity Framework 컨텍스트에 대한 기본 crud 메서드를 정의하는 RepositoryBase 클래스가 있습니다. 나는 모든() 메소드의 두 가지 오버로드가 있습니다리포지토리 메서드의 형식 유추
는public virtual IQueryable<T> All<TKey>(Expression<Func<T, bool>> predicate)
{
return All().Where(predicate);
}
public virtual PagedResult<T> All<TKey>(int startRowIndex, int maximumRows,
Expression<Func<T, TKey>> orderingKey, Expression<Func<T, bool>> predicate,
bool sortDescending = false)
{
var subset = All().Where(predicate);
IEnumerable<T> result = sortDescending
? subset.OrderByDescending(orderingKey).Skip(startRowIndex).Take(maximumRows)
: subset.OrderBy(orderingKey).Skip(startRowIndex).Take(maximumRows);
//More code ommited
}
첫 번째 방법은 항상 날이 명시 적으로 개체 유형을 지정해야하지만 두 번째는하지 않습니다. 왜 이런거야?
return All(s => s.LoanApplicationId == loanApplicationId)
을 대신 나는 다음과 같이 호출해야합니다 :
예,이 컴파일되지 않습니다
return All<LoanApplication>(s => s.LoanApplicationId == loanApplicationId)
을하지만 이것은 컴파일 않습니다 :
return All(0,10, s => s.Name, s => s.LoanApplicationId == loanApplicationId, false)