private OeEntryFactory CreateNestedEntryFactory(Type sourceType, IEdmEntitySet entitySet, ODataNestedResourceInfo resourceInfo)
        {
            ParameterExpression parameter = Expression.Parameter(typeof(Object));
            IReadOnlyList <MemberExpression> itemExpressions = OeExpressionHelper.GetPropertyExpression(Expression.Convert(parameter, sourceType));

            List <OeEntryFactory> navigationLinks = GetNavigationLinks(itemExpressions, parameter);

            OePropertyAccessor[] accessors;
            if (_pathSelect)
            {
                var accessorsList = new List <OePropertyAccessor>(_selectItemInfos.Count);
                for (int i = 0; i < _selectItemInfos.Count; i++)
                {
                    SelectItemInfo info = _selectItemInfos[i];
                    if (info.EdmProperty is IEdmStructuralProperty)
                    {
                        accessorsList.Add(OePropertyAccessor.CreatePropertyAccessor(info.EdmProperty, itemExpressions[i], parameter));
                    }
                }
                accessors = accessorsList.ToArray();
            }
            else
            {
                accessors = OePropertyAccessor.CreateFromExpression(itemExpressions[0], parameter, entitySet);
            }

            return(OeEntryFactory.CreateEntryFactoryNested(entitySet, accessors, resourceInfo, navigationLinks));
        }
Beispiel #2
0
        private OeEntryFactory CreateEntryFactoryFromTuple(OeEntryFactory parentEntryFactory)
        {
            OePropertyAccessor[] accessors = _allAccessors;
            if (IsTuple)
            {
                accessors = new OePropertyAccessor[_allAccessors.Length];
                OePropertyAccessor[] propertyAccessors = OePropertyAccessor.CreateFromType(ClrEntityType, EntitySet);
                for (int i = 0; i < accessors.Length; i++)
                {
                    OePropertyAccessor accessor = Array.Find(propertyAccessors, pa => pa.EdmProperty == _allAccessors[i].EdmProperty);
                    if (Array.IndexOf(Accessors, _allAccessors[i]) == -1)
                    {
                        var convertExpression   = (UnaryExpression)accessor.PropertyExpression.Expression;
                        var parameterExpression = (ParameterExpression)convertExpression.Operand;
                        accessor = OePropertyAccessor.CreatePropertyAccessor(accessor.EdmProperty, accessor.PropertyExpression, parameterExpression, true);
                    }
                    accessors[i] = accessor;
                }
            }

            var navigationLinks = new OeEntryFactory[NavigationLinks.Count];

            for (int i = 0; i < NavigationLinks.Count; i++)
            {
                navigationLinks[i] = NavigationLinks[i].CreateEntryFactoryFromTuple(this);
            }

            if (parentEntryFactory == null)
            {
                return(OeEntryFactory.CreateEntryFactoryParent(ClrEntityType, EntitySet, accessors, navigationLinks, null));
            }

            ParameterExpression parameter      = Expression.Parameter(typeof(Object));
            UnaryExpression     typedParameter = Expression.Convert(parameter, parentEntryFactory.ClrEntityType);
            MemberExpression    navigationPropertyExpression = Expression.Property(typedParameter, ResourceInfo.Name);
            LambdaExpression    linkAccessor = Expression.Lambda(navigationPropertyExpression, parameter);

            return(OeEntryFactory.CreateEntryFactoryNested(ClrEntityType, EntitySet, accessors, navigationLinks, linkAccessor, ResourceInfo));
        }