ToList()를 호출 할 때 런타임에 InvalidOperationException을 throw하는 LINQ 쿼리가 있는데 가능한 한 조인을 해제 할 필요없이 해결 방법을 찾으려고합니다. 별도의 where 절로.복합 키로 결합 할 때 InvalidOperationException이 발생합니다.
문제의 줄은 아래 예에서 3과 4입니다. loan_id는 null이 허용되지 않는 유형 십진수이며, ti_disb_id는 null 허용 불가능 유형 short입니다. 이들을 별도의 문장으로 분리하면 ToList()를 호출 할 때 예외가 없습니다. 그러나 그것은 함께 더 이해가되는 것처럼 보이므로, 해결책이 있다면 그것을 듣고 싶습니다. :)
var baseQuery = (from a in context.ti_disbursements
join b in context.disbursement_schedule
on new {a.loan_id, a.ti_disb_id} equals
new {b.loan_id, b.ti_disb_id} into ab
from b in ab.DefaultIfEmpty()
join c in context.business_associates
on a.ba_id equals c.ba_id into ac
from c in ac.DefaultIfEmpty()
join d in context.investor_loan
on b.loan_id equals d.loan_id into ad
from d in ad.DefaultIfEmpty()
join e in context.loan_information
on d.loan_id equals e.loan_id into ae
from e in ae.DefaultIfEmpty()
join f in context.loan_balances
on e.loan_id equals f.loan_id into af
from f in af.DefaultIfEmpty()
join g in context.ti_information
on e.loan_id equals g.loan_id into ag
from g in ag.DefaultIfEmpty()
select new
{
loan_id = a.loan_id,
ti_disb_id = a.ti_disb_id,
ti_freq_id = a.ti_freq_id,
ti_disbursements_stop_code = a.ti_stop_code,
tax_account_number = a.tax_account_number,
ti_disb_due_dt = b.ti_disb_due_dt,
ti_expire_dt = b.ti_expire_dt,
ti_disb_amt = b.ti_disb_amt,
schedule_id = b.schedule_id,
ba_name = c.ba_name,
inv_bank_cd = d.inv_bank_cd,
inv_cd = d.inv_cd,
inv_group_cd = d.inv_group_cd,
loan_name = e.loan_name,
prin_bal = f.prin_bal,
ti_bal = f.ti_bal,
ti_information_stop_code = g.ti_stop_cd,
non_escrowed_type = a.non_escrowed_type,
ba_type_id = a.ba_type_id,
bill_received_dt = a.bill_received_dt,
});
는 예외 메시지 :
InvalidOperation 예외는 구체화 된 값이 null이기 때문에 값 유형 캐스트 'INT16가'실패 사용자 코드
에 의해 처리되지 않은이었다. 결과 유형의 제네릭 매개 변수 또는 쿼리가 null 가능 유형을 사용해야합니다.
미리 감사드립니다.
데이터베이스에서 쿼리를 실행하여 결과 및 어떤 열이 null인지 확인합니다. null이 어디로 들어오는 지에 대한 힌트를 제공해야합니다. –
@GarrisonNeely 예외는 이미 모든 정보를 제공합니다 (실제로 3 또는 4 번째 라인에서 던져 졌다고 가정하면). 이것은 'ti_disb_id' values는 null입니다. – evanmcdonnal
@evanmcdonnal 그게 재밌 네요, 아무 값도 실제로 null입니다. 데이터베이스 값을 살펴본 결과 _supposed_라는 쿼리를 사용했습니다. _ 실제로 그 쿼리를 사용하든, 아직 알지 못했습니다. –