I’m having an odd situation with some LINQ that is not generating the response I expect.
The following groups in the way I’d expect (two groups: one for odd numbers, one for even numbers):
var ints = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
var foo = from i in ints
group i by i % 2 into g
select new {
Key = g.Key,
Group = g
};
When I do the following similar query on a MySQL database (using IQ Driver), it results in something completely unintuitive: a separate “group” for each entry in the database.
var bar = from f in MYDATABASE_TABLE.Take(10)
group f by f.Uid % 2 into g // where Uid is an int
select new {
Key = g.Key,
Group = g
};
Does any one have any ideas on why this is behaving so oddly? The GroupBy clause seems to be behaving weird if I add any sort of operation to it. (For example, you can try a random number generator for 0s and 1s (e.g. replace the “f.Uid % 2” clause with random.Next(1)), and it does something similar.)
Edit: Took out references to “linq-to-sql”, which turn out to be incorrect, and added explicit reference to IQ Driver.
Try this (untested, but I’ve done something similar):
I could be wrong about this, but it should be easy to try.