IN clause

5 posts, 1 answers
  1. Paul
    Paul avatar
    113 posts
    Member since:
    May 2009

    Posted 21 May 2009 Link to this post

    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
  2. Answer
    PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 21 May 2009 Link to this post

    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.
  3. DevCraft banner
  4. Paul
    Paul avatar
    113 posts
    Member since:
    May 2009

    Posted 21 May 2009 Link to this post

    Hi Petar,
                 Thats perfect and works great thanks.

    Regards,
    Paul.
  5. Devanand Chahal
    Devanand Chahal avatar
    26 posts
    Member since:
    Mar 2009

    Posted 26 Aug 2010 Link to this post

    Hi Peter,

     

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

    Thanks

    Devanand

  6. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 06 Oct 2010 Link to this post

    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
Back to Top
DevCraft banner