Linq to SQL left join, take the right table possible null int Type field

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.