query with multiple conditions

Sep 29, 2010 at 9:21 AM


I would create a query with multiple conditions but I don't know a priori how many conditions I have:

let's suppose I have the possibility to choose some items within a listbox, each of which has an ID. Then I want to make a query on selected IDs.

I have something similar to the following:


public MainCategory[] GetSummary(int [] IDs) {

 MainCategory[] mainCategories


 var query = (from oneMainCategory in db.Table<MainCategory>()


oneMainCategory.ID == ( all IDs )

 select oneMainCategory);

... other code ... 

return mainCategories;


I would have no problem in building up this query in PHP, but it is not clear to me how to do it in C# since I cannot concatenate strings...

Can you, please, help me?


Sep 30, 2010 at 1:58 AM

Here is code sample:


public class Category
            public int CategoryID { getset; }
            public string CategoryName { getset; }

        private void Test()
            string dbn = Guid.NewGuid().ToString();
            Database db = Database.CreateDatabase(dbn);

            if (db.Table<Category>() != null)
                for (int i = 0; i < 20; i++)
                    db.Table<Category>().Add(new Category() { CategoryID = i, CategoryName = i.ToString() });

                int[] ids = new int[] { 1, 2, 3 };
                var thing = (from oneid in ids
                             join oneCat in db.Table<Category>() on oneid equals oneCat.CategoryID
                             select oneCat).ToList();