2

Suppose i have the following

var mustHave = new int [] { 1, 2 }

and a table named db.Numbers

public class Number
{
     public int id;
     public int number;
}

populated with

Numbers.add(new Number(){id=8,number=1});
Numbers.add(new Number(){id=8,number=2});
Numbers.add(new Number(){id=8,number=3});
Numbers.add(new Number(){id=9,number=1});
Numbers.add(new Number(){id=9,number=3});

I want to get all ids which are associated to all numbers in the mustHave variable. For example The query must return id=8 but not id=9. The real case is much more complicated and does the query against a database with Linq-To-Sql.

TheSoftwareJedi
  • 34,421
  • 21
  • 109
  • 151
Jader Dias
  • 88,211
  • 155
  • 421
  • 625

2 Answers2

-1

Try this:

var numbers = Numbers.FindAll(n=>n.id=8);
var mustHave= new int[numbers.Count][2];
int counter = 0;`
foreach(var number in numbers)
{
    mustHave[counter][0]=number.id;
    mustHave[counter][1]=number.number;
    counter++;
 }
Eugeniu Torica
  • 7,484
  • 12
  • 47
  • 62
-1

Well if you're doing something in LINQtoSQL with a DataContext, try this:

var mustHave = new int [] { 1, 2 };
var items = 
  from x in DataContext.SomeTable
  where mustHave.Contains(x.SomeProperty)
  select x;
Matt Culbreth
  • 2,835
  • 2
  • 19
  • 17
  • Your query would return all ids that are associated to at least one of the mustHave array items. What I really want to do is a query that returns the ids that are associated to ALL mustHave array items. – Jader Dias May 18 '09 at 19:30