Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

s
Pritom Nandy
More...

Forums » .NET » ASP.NET »

How to form query dynamically for linq


Posted Date: 29 Jun 2012      Posted By:: AlluriAshokkumar     Member Level: Silver    Member Rank: 1728     Points: 5   Responses: 1



actually I am using Session Datatable

how select the multiple where conditions like

in Sql WHERE Name='' AND User='' AND Num=''

like
if (SearchDomains != "")
{
if (date1 != "" && date2 != "")
{
query = query + " and ";
}
query = query + "MyDomains LIKE '" + SearchDomains + "%'";

}
if (DomianStatus != "")
{
if (date1 != "" && date2 != "" || SearchDomains != "")
{
query = query + " and ";
}
query = query + "StatusToolTip ='" + DomianStatus + "'";
}
if (NoDays != "")
{
if (date1 != "" && date2 != "" || SearchDomains != "" || DomianStatus != "")
{
query = query + " and ";
}
Double Days = Convert.ToDouble(NoDays);
ExpSart = DateTime.UtcNow;
ExpEnd = DateTime.UtcNow.AddDays(Days);
query = query + "EndDate >='" + ExpSart + "' and EndDate <='" + ExpEnd + "' ";

}

how can i form this type of query in LINQ ,
how can i pass this query in linq




Responses

#678157    Author: Mohan M Devarinti      Member Level: Gold      Member Rank: 488     Date: 29/Jun/2012   Rating: 2 out of 52 out of 5     Points: 4

Hi,

you can try like this:

var result = from p in pssContext.Users
select p;
string strUid = "";
if (!string.IsNullOrEmpty(txtFilterName.Text))
{
result = result.Where(p => p.Name.Equals(txtFilterName.Text));
}
if (!string.IsNullOrEmpty(strUid))
{
result = result.Where(p => p.UserId.Equals(strUid));
}

if it vl not help this, then ref the link:
http://www.albahari.com/nutshell/predicatebuilder.aspx
http://www.albahari.com/nutshell/predicatebuilder.aspx


Regards,
Murali



 
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 : How catch results of stored procedure in asp.net page
Previous : Generate user name with a,b,c,d .......
Return to Discussion Forum
Post New Message
Category:

Related Messages
Active Members
TodayLast 7 Daysmore...

Awards & Gifts
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.