If you pass in an array of value types to the constructor of Entity Key, you get an exception. For example:
var myKeyValues = new [] {123, 456}; //Compiler decides this should be an int[]var key = new EntityKey(typeof(MyEntity), myKeyValues); |
The EntityKey constructor will throw an exception like:
System.InvalidCastException: Unable to cast object of type 'System.Int32[]' to type 'System.Object[]'. at IdeaBlade.EntityModel.EntityKey..ctor(Type entityType, Object aValue, Boolean convertValue) |
Looking at it in Reflector, it seems that constructor assumes that if the passed in value is an Array, it can safely cast it to an object array (object[]). But that is only true if the source array is of reference types (which is not the case in my example because I'm passing in an array of ints).
The workaround for this is pretty easy but I think it's still worth fixing (we just ran into this in a part of our code that doesn't get hit very often so we 'forgot' to use the workaround). For reference, the following code will work without a problem.