where clause in linq query

Posted by masoud on Stack Overflow See other posts from Stack Overflow or by masoud
Published on 2012-10-18T04:58:42Z Indexed on 2012/10/18 5:00 UTC
Read the original article Hit count: 105

Filed under:
|

in the below code "transmittalno.TransID" always has value but "doctranstocon.Transid" sometimes has value and sometimes does not, so when "doctranstocon.Transid" has value I have no problem but when there is not any value, when compare in the where clause like :"transmittalno.TransID == doctranstocon.Transid". It returns error" Object reference not set to an instance of an object."

TranstoCons = from doctranstocon in _DocTranstoCons where 
                                                          ( transmittalno.TransID == doctranstocon.Transid  ) select doctranstocon.tblTranstoCon

I like TranstoCons returns null when there is not any value for " doctranstocon.Transid "

How I can handle this error in the below linq query:

var query = from transmittalno in _Transmittals

                    Select new TransmittaltoConPresentationModel { TransID = transmittalno.TransID, Transmittal = transmittalno.TRANSMITTAL, TranstoCons = from doctranstocon in _DocTranstoCons where 
                                                          ( transmittalno.TransID == doctranstocon.Transid  ) select doctranstocon.tblTranstoCon };

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about LINQ