2
NULL 값을 포함 할 수있는 TradeNo라는 INT 필드가 있습니다. 요구 사항은 드롭 다운에 계약 ID 및 거래 NO를 괄호에 표시하고 거래 NO가 Null 인 경우 N/A를 표시하는 것입니다.LINQ & Entity Framework : NULL 값 연결 문제
Example:
44444 (2222)
55555 (N/A)
다음은 내가 생각했던 것입니다. 이것은 selectList의에게
public IEnumerable<SelectListItem> GetContractsBySupplierDropDown(string supplier)
{
var result = from c in context.Contracts
where c.Supplier==supplier
orderby c.ContractID
select new {
Text = c.ContractID.ToString() + " (" +
(c.TradeNo.HasValue ?
c.TradeNo.Value.ToString() :
" N/A ").ToString() +
")",
Value = c.ContractID };
return new SelectList(result, "Text", "Value");
}
오류를 반환 내 기능입니다 반환되는 것 :
내가 무엇을 말할 수에서LINQ to Entities does not recognize the method 'System.String ToString()'
method, and this method cannot be translated into a store expression.
, 오류가 EF 데이터베이스 기능에 ToString 변환을 시도하는 것을 의미 표시된?
나는이 접근법을 정말 좋아한다. Schiavini! – gmang