LINQ to SQL, the LINQ to entity encounters a problem with the primary table, from table to relationship, the primary table has records, and the table may not be logged.
Now you want to query the main Table + some fields from the table.
Is there a TZSBH int from the table field? Type. int to string if object is null, error
varQueryleft = fromCinchdb. AA Join SRinch ( fromSsinchdb. BBSelectss) on C.id equals Sr. Sid into X fromYinchX.defaultifempty ()Select New{c.id, c.timeflag, TZSBH =Y.TZSBH}; Result= fromCinchqueryleft.asenumerable ()Select NewShowinfo {Sid=c.id, Timeflag=C.timeflag, Pdfid=c.tzsbh.tostring ()//int to string this line, if the object is null, error };
Try the following scheme, left connection, 1 to many, take the right table FirstOrDefault, then judge Null, and then take the value
varSG = db. Aa. GroupJoin (db. BB, C = c.id, d = D.sid, (c, d) = =New{c.id, c.timeflag, Pdf = D.firstordefault ()}). Select (o =o); varresult = fromCinchsg. AsEnumerable ()Select NewShowinfo {Sid=c.id, Timeflag=C.timeflag, Pdfid= C.pdf = =NULL?"": C.pdf.tzsbh.tostring ()};
Linq to SQL left join, take the right table possible null int Type field