[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

LINQ question

Posted on 2016-11-08
7
Medium Priority
?
75 Views
Last Modified: 2016-11-08
Dear Experts,
How do I can combine the results in this LINQ query?

c.field == 1 below generates results and c.field == 3 generates results but how can I show the list of both results together. This below generates no results.  I guess one is cancelling out the other.

var today = DateTime.Now.Date;
var tomorrow = today.AddDays(1);

var query = from c in databasetable
						  where c.date > today && c.date < tomorrow
						  && c.field == 1 
						  && c.field == 3
						  select c;
						  
query.Dump();

Open in new window

0
Comment
Question by:sunny-j
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 32

Accepted Solution

by:
Pawan Kumar earned 2000 total points
ID: 41878272
Try..

var today = DateTime.Now.Date;
var tomorrow = today.AddDays(1);

var query = from c in databasetable
						  where c.date > today && c.date < tomorrow
						  && ( c.field == 1 
						  || c.field == 3 )
						  select c;
						  
query.Dump();

Open in new window

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41878280
>>I guess one is cancelling out the other.

Yes.  The && means and and c.field can't be equal to 1 and 3 and the same time.  The || (previous comment by the other expert) means or.  So it matches c.field to either 1 or 3
0
 

Author Comment

by:sunny-j
ID: 41878287
Thank you for your comments. I do want results from c.field == 1 and c.field == 3 (these are states in a picklist) so do I need to approach this differently, maybe by grouping the results.  The II will give me one or the other so doesn't solve my issue.  Any further help must appreciated.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41878298
On column c cannot have 2 values at the same time. It can either have 1 or 3 at the same time.  You need to create 2 queries and then perform your logic.

var today = DateTime.Now.Date;
var tomorrow = today.AddDays(1);

var query = from c in databasetable
						  where c.date > today && c.date < tomorrow
						  && ( c.field == 1 )						 
						  select c;

var query1 = from c in databasetable
						  where c.date > today && c.date < tomorrow
						  && ( c.field == 3 )						 
						  select c;
						  
query.Dump();
query1.Dump(); 

Open in new window

0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 41878301
Using the || operator will give from both c.field=1 and c.field=3.  Which is what you want you say.
1
 

Author Comment

by:sunny-j
ID: 41878307
ignore, the above worked. Thank you for your help.
0
 
LVL 32

Expert Comment

by:Pawan Kumar
ID: 41878311
Great ! Welcome !!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question