System.Linq.Dynamic.Core
System.Linq.Dynamic.Core copied to clipboard
Cannot cast 'object' type to 'Tuple<T1, T2, T3>'
I'm trying to run a dynamic query with a model as below:
public class Index
{
public long Position { get; set; }
public object[] Values { get; set; }
}
And with a sample of data like this:
var indexes = new Dictionary<long, Index>();
indexes.Add(1, new Index { Position = 1000, Values = new object[3] { "Welly", "Chandra", Tuple.Create<int, int>(1, 2) } });
indexes.Add(2, new Index { Position = 1001, Values = new object[3] { "Darma", "Angelo", Tuple.Create<int, int>(3, 4) } });
indexes.Add(3, new Index { Position = 1002, Values = new object[3] { "Abby", "Yeremia", Tuple.Create<int, int>(5, 6)} });
indexes.Add(4, new Index { Position = 1003, Values = new object[3] { "Yonathan", "Gunawan", Tuple.Create<int, int>(7, 8)} });
indexes.Add(5, new Index { Position = 1004, Values = new object[3] { "Aldy", "Santoso", Tuple.Create<int, int>(11, 12)} });
var queryable = indexes.Values.AsQueryable();
var result = queryable.Where("Values[1].Equals(\"Yeremia\") || ((Tuple<int, int>) Values[2]).Item2.Equals(8)").ToList();
But it always throw an exception:
Exception: No property or field 'Tuple' exists in ...
Is it not possible to use type-casting while querying here?
This issue contains two problems :
- Tuple is not recognized
- A generic cast is not suported?