mduffin Ответов: 0

Как включить свойство навигации в конструктор предикатов (поиск) concat (EF 6)


I'm enhancing a search predicate builder to concat navigation string fields along with the other entity string fields. Hoping to get guidance on modifying the concat expression for the included navigation properties. ProxyCreationEnabled is disabled for straight forward binding from the Entity to Asp.net controls. Passing a property name of "NavigationName.NavigationProperty" in the propertyNames string array results in an error (property is not a property of type T). Currently the concat expression is:

 <pre lang="c#">
public static Expression<Func<T, string>> GenerateConcat<T>(IEnumerable<string> propertyNames)
        {
            ParameterExpression parameter = Expression.Parameter(typeof(T), "m");
            ConstantExpression separator = Expression.Constant(" ");
            NewArrayExpression concatArgs = Expression.NewArrayInit(typeof(string),
                                                                    propertyNames
                                                                        .SelectMany(name => new Expression[]
                                                                        {
                                                                            separator,
                                                                            Expression.PropertyOrField(
                                                                                parameter,
                                                                                name)
                                                                        })
                                                                        .Skip(1));
            MethodCallExpression concatCall =
                Expression.Call(typeof(string).GetMethod("Concat", new[] {typeof(string[])}) ??
                                throw new InvalidOperationException(),
                                concatArgs);
            return Expression.Lambda<Func<T, string>>(concatCall, parameter);
        }


Возможно ли это?

Что я уже пробовал:

Я попробовал несколько вариантов, но пока безуспешно.

0 Ответов