Ejemplo n.º 1
0
        public OeEntryFactory CreateEntryFactory(Type entityType, IEdmEntitySetBase entitySet, Type sourceType)
        {
            ParameterExpression parameter = Expression.Parameter(typeof(Object));
            IReadOnlyList <MemberExpression> itemExpressions = OeExpressionHelper.GetPropertyExpression(Expression.Convert(parameter, sourceType));

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

            if (_pathSelect)
            {
                var accessors = new List <OePropertyAccessor>(_selectItemInfos.Count);
                for (int i = 0; i < _selectItemInfos.Count; i++)
                {
                    SelectItemInfo info = _selectItemInfos[i];
                    if (info.EdmProperty is IEdmStructuralProperty)
                    {
                        accessors.Add(OePropertyAccessor.CreatePropertyAccessor(info.EdmProperty, itemExpressions[i], parameter));
                    }
                }
                entryFactory = OeEntryFactory.CreateEntryFactoryParent(entitySet, accessors.ToArray(), navigationLinks);
            }
            else
            {
                OePropertyAccessor[] accessors = OePropertyAccessor.CreateFromType(entityType, entitySet);
                entryFactory = OeEntryFactory.CreateEntryFactoryParent(entitySet, accessors, navigationLinks);
                entryFactory.LinkAccessor = (Func <Object, Object>)Expression.Lambda(itemExpressions[0], parameter).Compile();
            }
            return(entryFactory);
        }
Ejemplo n.º 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));
        }