-1

The syntax given for contains clause is

ids = new int[] {1,2,3,4};
dataContext.Table.Where("@0.Contains(id)", ids);

But what I want is

dataContext.Table.Where("{1,2,3,4}.Contains(id)"); //getting exception here

[ERROR] Expression expected (at index 0)

I need this because the where clause my or may not use the contains method. it depends on how user acts.

Sujit.Warrier
  • 2,815
  • 2
  • 28
  • 47

2 Answers2

0

so I got the answer for this after tinkering for sometime. So posting the answer here.

 dataContext.Table.Where("new Int[]{1,2,3,4}.Contains(id)");

You can use whatever datatype you need. I use reflection to find datatype and use that accordingly.

Sujit.Warrier
  • 2,815
  • 2
  • 28
  • 47
0

try code:

int[] ids= {1,2,3,4};

dataContext.Table.Where(c=>c.ids.Contains(t.id)).ToList();

Or

var result= (from p in dataContext.Table.AsEnumerable()
                      join q in ids on p.id equals q
                        select p).Distinct() .ToList();
kari kalan
  • 497
  • 3
  • 20