Issue with AsQueryable()
I had an issue using AsQueryable() in some of my code. What I was trying to do is this:
CustomerDAL customers = new CustomerDAL(this.DataContext);
short key1 = customers.GetPrimaryContact(selectedCustomer).CustomerKey;
short key2 = customers.GetSecondaryContact(selectedCustomer).CustomerKey;
return new short[] { key1, key2 }.AsQueryable();
The results were returned to the keys variable, and I used them in a query like so:
where ...
&& !keys.Contains(c.CustomerKey) //produced StackOverflowException
But this kept throwing a stack overflow exception, and I couldn't figure out why. I would comment out that line above and it would work without that contains. Later I figured out that AsQueryable() was the problem; simply removing it, and returning an IEnumerable result worked perfectly. So be careful with AsQueryable in your use of it; in some scenarios, it may be a problem.
If someone knows the reason why, please post a comment, as I would be interested to know what that is an issue.