Avatar of Robb Hill
Robb HillFlag for United States of America

asked on 

Linq Testing null

I have the following statement..what is the best way to handle this syntactfully speaking.

Below data is a string value.  I am trying to convert the string to an int so it can be used in the linq comparison.
What is the best way to do this...and also trapping for the variable data to be null.  So I imagine I would not want to try and assign ndocument should data be null...but then I also would not want to execute the linq statement either.

Also this would just return one row....does it make sense to use firstordefault in this case?



 var ndocument = Convert.ToInt32(data);

            var fileContext = (from f in this.AppServiceEFCodeFirst.sqlDb.Documents
                               where f.DocumentId == ndocument
                               select f).FirstOrDefault();

Open in new window

LINQ Query.NET ProgrammingC#

Avatar of undefined
Last Comment
Fernando Soto
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Robb Hill
Robb Hill
Flag of United States of America image

ASKER

Thank you!
Avatar of Robb Hill
Robb Hill
Flag of United States of America image

ASKER

Thanks a billion
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Not a problem Robb, glad I was able to help.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo