{x => x.principal_info.First().agent_for_property_info
Все работает так, как ожидалось.
На самом деле мне нужно преобразовать его в IEnumerable вместо ICollection, как вы можете видеть здесь.
Вот метод, который работает:
Код: Выделить всё
public Expression GetGenericExpression(bool first = false, params string[] properties)
{
var expression = GetNavigationPropertySelector(typeof(T), first, properties);
var expRight = (Expression)expression;
return expRight;
}
{x => x.principal_info.First().agent_for_property_info
Когда я провожу кастинг:
Код: Выделить всё
var expRight = (Expression)expression;
Код: Выделить всё
Unable to cast object of
type
'System.Linq.Expressions.Expression`1[System.Func`2[SomeModel1,
System.Collections.Generic.ICollection`1[SomeModel]]]'
to type
'System.Linq.Expressions.Expression`1[System.Func`2[SomeModel1
,System.Collections.Generic.IEnumerable`1[SomeModel]]]'.
Я много исследовал, но не нашел решения, как привести ICollection к IEnumerable и возможно ли это вообще?
Фактически, компилятор может привести его неявно, поскольку эти строки действительны:
Код: Выделить всё
var queryData1 = new QueryData()
{
WhereClause = expression,
SelectClause = info => info.principal_info.First().agent_for_property_info
};
info => info.principal_info.First().agent_for_property_info
Подробнее здесь: https://stackoverflow.com/questions/521 ... numerablet