This is a migrated thread and some comments may be shown as answers.

IN clause

4 Answers 99 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 21 May 2009, 12:54 PM
Hi,
    In sql I can get records by a collection of ids like this
SELECT resourcelibrary.* from resourcelibrary where ResourceID in ( 1,5,7,9,32)  
 

How can I do this in OQL or linq?

Thanks

4 Answers, 1 is accepted

Sort by
0
Accepted
PetarP
Telerik team
answered on 21 May 2009, 01:48 PM
Hi Paul,
here is a sample code snippet for achieving your goal using LINQ:
 IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); 
            List<int> myList = new List<int>() { 1, 2, 3, 4 };             
            var result = from c in scope.Extent<Category>() 
                         where myList.Contains(c.CategoryID) 
                         select c;            
            foreach (Category ct in result) 
            { 
                Console.WriteLine(ct.CategoryID); 
            } 
Note that the Category table from Northwind database is used in the above example.

Regards,
PetarP
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul
Top achievements
Rank 1
answered on 21 May 2009, 01:53 PM
Hi Petar,
             Thats perfect and works great thanks.

Regards,
Paul.
0
Devanand Chahal
Top achievements
Rank 2
answered on 26 Aug 2010, 10:11 AM

Hi Peter,

 

If I need to build a expression for IN clause dynamically using Expression tree, Then how can I acheive this.

Thanks

Devanand

0
PetarP
Telerik team
answered on 06 Oct 2010, 06:09 PM
Hi Devanand Chahal,

 I believe that you will find the following topic useful as it discuss how to use expression trees to build dynamic queries.

All the best,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Getting Started
Asked by
Paul
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Paul
Top achievements
Rank 1
Devanand Chahal
Top achievements
Rank 2
Share this question
or