dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersMore...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Forums » .NET » LINQ »

Nullable IEnumerable Int32 comparison with null


Posted Date: 26 Mar 2012      Posted By:: Preet     Member Level: Gold    Member Rank: 79     Points: 4   Responses: 2



I am executing a sql query from linq to sql (dataContext). the query is returning either an int32 value of a null, that is why I defined the result return type as nullable int32.
But how to compare the result with null?

var retuls = dataContext.ExecuteQuery<Int32?>
("Select id from table where value={0}", value);

if(id == null_
return true;
else
return false;

Please suggest




Responses

#663350    Author: Gangadhara Deepadiah      Member Level: Gold      Member Rank: 613     Date: 26/Mar/2012   Rating: 2 out of 52 out of 5     Points: 3

Hi,

var retuls = dataContext.ExecuteQuery<Int32?> will return you object of type
IEnumerable<Int32?> (same as IEnumerable<int?>

If you are expecting only one element/ or required to chaeck the first element in the collection you ca do this

foreach(int i in retuls)
{
if(i.HasValue()) //if id is not null
{
return false;
}else
{
return true
}
}

return true;
Thanks

Thanks
Gags



 
#663368    Author: Anil Kumar Pandey      Member Level: Platinum      Member Rank: 1     Date: 26/Mar/2012   Rating: 2 out of 52 out of 5     Points: 2

You can check the NULL at object level directly.



var retuls = dataContext.ExecuteQuery<Int32?>
("Select id from table where value={0}", value);

if(result!= Null)
{
//Call items here
}


Thanks & Regards
Anil Kumar Pandey
Microsoft MVP, DNS MVM



 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Inner join in linq sql using wp7
Previous : How to write 3tier architecture
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.