Click here to Skip to main content
16,004,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to write a query in linq but I stuck how to use between and like in the same query.

My sql query is:

SQL
Select r.Name, r.number
from records r
where (r.datePurchased BETWEEN '03/03/2012%' AND '05/03/2012%') AND r.Code=4


can someone help me write it in Linq. Thanks in advance.
Posted
Updated 31-Mar-17 2:22am

Have a look at this[^] little tool.
 
Share this answer
 
Comments
wonder-FOOL 14-Mar-12 15:57pm    
You posted the same link with Uday later than 2 mins but I will give you the credit also :) Thanks for the link.
Try this:

SQL to LINQ converter[^]

hope it helps :)
 
Share this answer
 
Comments
wonder-FOOL 14-Mar-12 15:58pm    
Thank you.
I use extension methods, and SQL like may be better for you:

SQL
r.Where(
       i => i.datePurchased >= new DateTime(2012, 03, 03) &&
       i.datePurchased <= new DateTime(2012, 05, 03) && i.Code == 4)
                .Select(i => new {i.datePurchased, i.Number});
 
Share this answer
 
Comments
wonder-FOOL 14-Mar-12 15:58pm    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900