none
join using dot notation and not exists RRS feed

  • Question

  • So I have 2 database tables. One with all the selectable items. And then another table with the selected items for each item.

    I've got 2 listboxes. One that displays the selectable items and then on the right are the already selected items. As items are selected they are removed from the selectable listbox.

    I know I could just populate the listbox with something like this

    listbox.Items.AddRange(dc.Items.Select(s=>s.ItemName).ToArray());

    This works fine. What I want to do is a join to the Already Selected items table. Something like this is SQL

    SELECT s.ItemName
    FROM Items s
    WHERE NOT EXISTS (SELECT 1 FROM SelectedItems si
    where si.ItemID = s.ItemID)

    Currently I'm doing the following which works
      var skills = (from s in ddDL.skills()
                    where !(from cs in ddDL.CreatureSkills(_currentID)
                            select cs.SkillID).Contains(s.SkillID)
                      select s);
      lstSkills.Items.AddRange(skills.Select(s=>s.Skill1).ToArray());

    But I prefer to do it as one state using dot notation.

    Next, the selectedItems. It's in a listview. It should have 2 columns, the name and a value
    I do the following which populates the first column with the name, but how do I get my subitems
    IEnumerable<ListViewItem> myResultList = ddDL.skills().Join(ddDL.CreatureSkills(_currentID), s => s.SkillID, cs => cs.SkillID, (s, cs) => new { Name = s.Skill1, Amount = cs.Skill_Amount })
        .Select(scs => new ListViewItem() { Text = scs.Name });

    lvCreatureSkills.Items.Clear();
    lvCreatureSkills.Items.AddRange(myResultList.ToArray());

    Any help is appreciated

    Joe


    Joe Pacelli
    Friday, July 16, 2010 10:03 PM

Answers

All replies