Disclaimer: I already checked this question but this is about the Immediate window.
I'm using Entity Framework to fetch some results, so I have a list of logging:
var result = ctx.Logging.Where(*filtering*).ToList();
But I want to know the distinct Datatypes of the list (an enumeration, underlying type byte and Datatype
is nullable, if I make it not nullable it works for some reason). When I try to do it in the immediate window:
result.Select(r => r.Datatype).Distinct().ToList();
I get the message:
Internal error in the expression evaluator.
However it works fine when I do it in code, for example var test = result.Select(r => r.Datatype).Distinct().ToList();
. I already tried using 'managed compatibility mode' and 'legacy expressions' from the debugging options but then I get another message:
Expression cannot contain lambda expressions
Am I missing something or is this a bug in Visual studio 2015?
Minimal, Complete, and Verifiable example:
class Program
{
static void Main(string[] args)
{
List<Test> tests = new List<Test>();
for(int i = 0; i<100; i++)
{
if (i % 2 == 0)
tests.Add(new Test { ID = i, Enum = TestEnum.Value1 });
else
tests.Add(new Test { ID = i, Enum = TestEnum.Value2 });
}
var distinct = tests.Select(t => t.Enum).Distinct().ToList();
}
}
public enum TestEnum : byte
{
Value1 = 1,
Value2 = 2
}
public class Test
{
public int ID { get; set; }
public TestEnum? Enum { get; set; }
}
In code tests.Select(t => t.Enum).Distinct().ToList();
works, in immediate window it doesn't.