mardi 4 août 2015

String Comparison in LINQ to SQL result null

I have two string array and want to see if there are any intersection or not. I am using linq to sql in c# and fetch the database field and compare it with the user input as below :

string[] Materials = material.Split('-');
                    AllItems = (from item in AllItems
                                where item.Material.Split(',').Intersect(Materials).Count() != 0
                                select item).ToList();

Materials are user input string which has - delimiter and in database I have string with , delimiter.

I wonder why the result is always null !!! I mean the query result says there is no intersection but I check and there is !!!

another alternative query that I used and take the same result was this :

string[] Materials = material.Split('-');
                    HashSet<string> stringSet = new HashSet<string>(Materials);
                    AllItems = (from item in AllItems
                                where item.Color.Split(',').Where(c => stringSet.Contains(c)).Count() != 0
                                select item).ToList();

I am so confused whats the problem with these quries !!! I should mention that the strings are UTF8 one and contains 2 bytes character in persian language, I guess maybe It's the problem but I don't know how to solve it.

Is there any solutions? Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire