1
이 쿼리를 작성하는 더 간단한 방법이 있습니까? 내 논리는 입니다. 컬렉션에 고객 ID와 국가 코드가 포함되어 있으면 고객 ID로 오름차순으로 쿼리를 수행하십시오. CustID에 ID가 들어 있지 않으면 고객 이름순으로 주문하십시오. 이 쿼리를 작성하는 더 좋은 방법이 있습니까? 난 복잡한 람다에 익숙하지 않아.이 LINQ 쿼리를 작성하는 더 좋은 방법이 있습니까?
var custIdResult = (from Customer c in CustomerCollection
where (c.CustomerID.ToLower().Contains(param.ToLower()) &&
(countryCodeFilters.Any(item => item.Equals(c.CountryCode))))
select c).ToList();
if (custIdResult.Count > 0)
{
return from Customer c in custIdResult
where (c.CustomerName.ToLower().Contains(param.ToLower()) &&
countryCodeFilters.Any(item => item.Equals(c.CountryCode)))
orderby c.CustomerID ascending
select c;
}
else
{
return from Customer c in CustomerCollection
where (c.CustomerName.ToLower().Contains(param.ToLower()) &&
countryCodeFilters.Any(item => item.Equals(c.CountryCode)))
orderby c.CustomerName descending
select c;
}
내 뇌가 동결되고 이런 식으로 생각합니다 :) 우수 . 고마워. – Spock