3
I need help, I’m starting in development, eclistIds
returns me two ids, and if I don’t use the negation ( ! ) it returns me the id I don’t want, when I use the negation to return the other id, according to the leftjoin
, error occurs
My ids are decimal
List<ExtraModel> add= (from fpp in ADD
join fpc in FPC
on new { fpp.fpId, fpp.etId }
equals new { fpc.fpId, fpc.etId }
join ec in EP on fpc.ecId equals ec.ecId
join fpcp in FPCP
on new { fpp.fppId, fpc.ecId }
equals new { fpcp.fppId, fpcp.ecId } into x
from d in x.DefaultIfEmpty()
where fpp.fpId == FPId
&& fplistIds.Contains(fpp.fpId)
&& etlistIds.Contains(fpp.etId)
&& !eclistIds.Contains(d.ecId)
select new ExtraModel {
fppId = d.fppId,
ecId = d.ecId }).ToList();
The error that appears is as follows:
The cast to value type 'System.Decimal' failed because the materialized value is null. Either the result type's generic parameter or the query must use a nullable type.
SOLUTION!
var fpcpAdd = (from fpp in FPP
join fpc in FPC
on new { fpp.fpId, fpp.etId }
equals new { fpc.fpId, fpc.etId }
join fpcp in FPCP
on new { fpp.fppId, fpc.ecId }
equals new { fpcp.fppId, fpcp.ecId } into x
from d in x.DefaultIfEmpty()
where fpp.fpId == fpId
&& fpIds.Contains(fpp.fpId)
&& etIds.Contains(fpp.etId)
&& ecIds.Contains(fpc.ecId)
&& fpp.fppId != d.fppId
select new {
fpp.fppId,
fpc.ecId }).ToList();
THANK YOU ALL!
This problem, I believe, is not no contains, but conversion.
– Augusto Henrique
According to the error, the problem is in converting a null value to Decimal.
– Focos
You will have decimal values to null in the query return you should put in your Extramodel class the fields fppId and ecid as Decimal?
– Ricardo
Perfect, thanks, but how do I fix it?
– Alexandre Moss
Ricardo I can’t change the extraModel because it’s a big system and it causes several errors .... The solution would have to be in Brasili
– Alexandre Moss