Subscribe to Subscribers
Talk to Webmaster Tony John


Forums » .NET » LINQ »

Dynamic Query creation in Linq.


Posted Date: 08 Apr 2010      Posted By:: Kunal     Member Level: Bronze    Member Rank: 0     Points: 1   Responses: 1



i am using .net freamwork 3.5
i want to find data from sqlserver database.
i want to do it useing dynamic linq.
is it possible? if yes then how?




Responses

#491680    Author: Tejas Trivedi      Member Level: Gold      Member Rank: 136     Date: 08/Apr/2010   Rating: 2 out of 52 out of 5     Points: 2

Hi,

yes, it is possible to have dynamic query while using linq to sql.

The Dynamic Expression API provides IQueryable Extension Methods as part of System.Linq.Dynamic.DynamicQueryable class for dynamically querying objects.

We can construct the above query using the IQueryable extension method Where() like below:

DataClassesDataContext db=new DataClassesDataContext();
var products = db.Products
.Where("Model==@0 && onsale==@1","SD1000", true) ;


also, it is possible to make whole condition string dynamically.

DataClassesDataContext db=new DataClassesDataContext();
string condition = "Model==\"SD1000\" && onsale==true ";
var products = db.Products.Where(condition );


Thanks.

Regards,
Tejas

Thanks & Regards
Tejas
[Don't just write Softwares,Write an innovative solutions.]



 
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 : Readind data from XML and copying to an array or object
Previous : Avoid Looping
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
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.