1

i have 2 tables: Item and Category with fields (pseudo code):

Item
----------
int ItemId
Category Category
(etc...)

Category
----------
string Name
bool IsSelected
(etc...)

I would like to retrieve from DB all Items where category has flag IsSelected = true.

For testing first I create Items:

Category category = new Category() { Name = "test_name", IsSelected = true };
db.CategoriesTable.InsertOnSubmit(category);
db.SubmitChanges();
for(int i = 0; i < 10; i++) {
    Item item = new Item() { Category = category };
    db.ItemsTable.InsertOnSubmit(item);
}
db.SubmitChanges();

Now I have 10 Items with category with IsSelected = true.

When I want to retrieve all Items with category with IsSelected == true, I write:

Array<Item> items = ItemsTable.Where(f => f.Category.IsSelected).ToArray();

And I expected 10 items, but I got only 1 item - the first one! Why? I checked data in table and every item has the same category, so I guess that query is wrong...

4

0 回答 0