I got one big question.
I got a linq query to put it simply looks like this:
from xx in table
where xx.uid.ToString().Contains(string[])
select xx
The values of the string[]
array would be numbers like (1,45,20,10,etc...)
the Default for .Contains
is .Contains(string)
.
I need it to do this instead: .Contains(string[])
...
EDIT : One user suggested writing an extension class for string[]
. I would like to learn how, but any one willing to point me in the right direction?
EDIT : The uid would also be a number. That's why it is converted to a string.
Help anyone?
Linq extension method. Will work with any IEnumerable object:
Usage:
Try the following.
I managed to find a solution, but not a great one as it requires using AsEnumerable() which is going to return all results from the DB, fortunately I only have 1k records in the table so it isn't really noticable, but here goes.
My original post follows:
I believe that what you really want to do is: let's imagine a scenario you have two database and they have a table of products in common And you want to select products from the table "A" that id has in common with the "B"
using the method contains would be too complicated to do this what we are doing is an intersection, and there is a method called intersection for that
an example from msdn: http://msdn.microsoft.com/en-us/vcsharp/aa336761.aspx#intersect1
int [] numbers = (0, 2, 4, 5, 6, 8, 9); int [] numbersB = (1, 3, 5, 7, 8); var = commonNumbers numbersA.Intersect (numbersB);
I think what you need is easily solved with intersection
If you are truly looking to replicate Contains, but for an array, here is an extension method and sample code for usage:
How about: