private EntityCollection NavigateToCollection(EntityCollection rootCollection, IEnumerable<string> segments)
        {
            if (!segments.Any())
                return rootCollection;

            var associationName = GetNavigationPropertyExactName(rootCollection.Name, segments.First());
            var typeName = IsSingleSegmentWithTypeSpecification(segments)
                ? segments.Last()
                : GetNavigationPropertyPartnerTypeName(rootCollection.Name, associationName);
            var entityCollection = GetEntityCollection(typeName);

            return segments.Count() == 1 || IsSingleSegmentWithTypeSpecification(segments)
                ? entityCollection
                : NavigateToCollection(entityCollection, segments.Skip(1));
        }
 public EntityCollection GetDerivedEntityCollection(EntityCollection baseCollection, string entityTypeName)
 {
     var actualName = GetDerivedEntityTypeExactName(baseCollection.Name, entityTypeName);
     return new EntityCollection(actualName, baseCollection);
 }
 public EntityCollection NavigateToCollection(EntityCollection rootCollection, string path)
 {
     return NavigateToCollection(rootCollection, GetCollectionPathSegments(path));
 }
        private EntityCollection NavigateToCollection(ExpressionContext context, EntityCollection rootCollection, string path)
        {
            var items = path.Split('/');
            var associationName = context.Session.Metadata.GetNavigationPropertyExactName(rootCollection.Name, items.First());

            var entityCollection = context.Session.Metadata.GetEntityCollection(
                context.Session.Metadata.GetNavigationPropertyPartnerName(rootCollection.Name, associationName));

            if (items.Count() == 1)
            {
                return entityCollection;
            }
            else
            {
                path = path.Substring(items.First().Length + 1);
                return NavigateToCollection(context, entityCollection, path);
            }
        }
        private IEnumerable<string> BuildReferencePath(List<string> segmentNames, EntityCollection entityCollection, List<string> elementNames, ExpressionContext context)
        {
            if (!elementNames.Any())
            {
                return segmentNames;
            }

            var objectName = elementNames.First();
            if (entityCollection != null)
            {
                if (context.Session.Metadata.HasStructuralProperty(entityCollection.Name, objectName))
                {
                    var propertyName = context.Session.Metadata.GetStructuralPropertyExactName(
                        entityCollection.Name, objectName);
                    segmentNames.Add(propertyName);
                    return BuildReferencePath(segmentNames, null, elementNames.Skip(1).ToList(), context);
                }
                else if (context.Session.Metadata.HasNavigationProperty(entityCollection.Name, objectName))
                {
                    var propertyName = context.Session.Metadata.GetNavigationPropertyExactName(
                        entityCollection.Name, objectName);
                    var linkName = context.Session.Metadata.GetNavigationPropertyPartnerName(
                        entityCollection.Name, objectName);
                    var linkedEntityCollection = context.Session.Metadata.GetEntityCollection(linkName);
                    segmentNames.Add(propertyName);
                    return BuildReferencePath(segmentNames, linkedEntityCollection, elementNames.Skip(1).ToList(), context);
                }
                else if (IsFunction(objectName, context))
                {
                    var formattedFunction = FormatAsFunction(objectName, context);
                    segmentNames.Add(formattedFunction);
                    return BuildReferencePath(segmentNames, null, elementNames.Skip(1).ToList(), context);
                }
                else if (context.Session.Metadata.IsOpenType(entityCollection.Name))
                {
                    segmentNames.Add(objectName);
                    return BuildReferencePath(segmentNames, null, elementNames.Skip(1).ToList(), context);
                }
                else
                {
                    throw new UnresolvableObjectException(objectName, string.Format("Invalid referenced object {0}", objectName));
                }
            }
            else if (FunctionMapping.ContainsFunction(elementNames.First(), 0))
            {
                var formattedFunction = FormatAsFunction(objectName, context);
                segmentNames.Add(formattedFunction);
                return BuildReferencePath(segmentNames, null, elementNames.Skip(1).ToList(), context);
            }
            else
            {
                segmentNames.AddRange(elementNames);
                return BuildReferencePath(segmentNames, null, new List<string>(), context);
            }
        }
Пример #6
0
 protected string FormatExpandItem(KeyValuePair <string, ODataExpandOptions> pathWithOptions, EntityCollection entityCollection)
 {
     return(FormatNavigationPath(entityCollection, pathWithOptions.Key));
 }
Пример #7
0
        protected string FormatOrderByItem(KeyValuePair <string, bool> pathWithOrder, EntityCollection entityCollection)
        {
            var items = pathWithOrder.Key.Split('/');

            if (items.Count() == 1)
            {
                var clause = _session.Metadata.HasStructuralProperty(entityCollection.Name, pathWithOrder.Key)
                    ? _session.Metadata.GetStructuralPropertyExactName(entityCollection.Name, pathWithOrder.Key)
                    : _session.Metadata.HasNavigationProperty(entityCollection.Name, pathWithOrder.Key)
                    ? _session.Metadata.GetNavigationPropertyExactName(entityCollection.Name, pathWithOrder.Key)
                    : pathWithOrder.Key;
                if (pathWithOrder.Value)
                {
                    clause += " desc";
                }
                return(clause);
            }
            else
            {
                var associationName = _session.Metadata.GetNavigationPropertyExactName(entityCollection.Name, items.First());
                var text            = associationName;
                var item            = pathWithOrder.Key.Substring(items.First().Length + 1);
                entityCollection = _session.Metadata.GetEntityCollection(
                    _session.Metadata.GetNavigationPropertyPartnerTypeName(entityCollection.Name, associationName));
                return(string.Format("{0}/{1}", text,
                                     FormatOrderByItem(new KeyValuePair <string, bool>(item, pathWithOrder.Value), entityCollection)));
            }
        }
Пример #8
0
 protected abstract void FormatExpandSelectOrderby(IList <string> commandClauses, EntityCollection resultCollection, FluentCommand command);
Пример #9
0
        protected string FormatOrderByItem(KeyValuePair <string, bool> pathWithOrder, EntityCollection entityCollection)
        {
            var items = pathWithOrder.Key.Split('/');

            if (items.Count() == 1)
            {
                var clause = _session.Metadata.HasStructuralProperty(entityCollection.Name, pathWithOrder.Key)
                    ? _session.Metadata.GetStructuralPropertyExactName(entityCollection.Name, pathWithOrder.Key)
                    : _session.Metadata.HasNavigationProperty(entityCollection.Name, pathWithOrder.Key)
                    ? _session.Metadata.GetNavigationPropertyExactName(entityCollection.Name, pathWithOrder.Key)
                    : pathWithOrder.Key;
                if (pathWithOrder.Value)
                {
                    clause += " desc";
                }
                return(clause);
            }
            else
            {
                if (_session.Metadata.HasNavigationProperty(entityCollection.Name, items[0]))
                {
                    var associationName = _session.Metadata.GetNavigationPropertyExactName(entityCollection.Name, items[0]);
                    var text            = associationName;
                    var item            = pathWithOrder.Key.Substring(items.First().Length + 1);
                    entityCollection = _session.Metadata.GetEntityCollection(
                        _session.Metadata.GetNavigationPropertyPartnerTypeName(entityCollection.Name, associationName));
                    return($"{text}/{FormatOrderByItem(new KeyValuePair<string, bool>(item, pathWithOrder.Value), entityCollection)}");
                }
                else if (_session.Metadata.HasStructuralProperty(entityCollection.Name, items[0]))
                {
                    var clause = _session.Metadata.GetStructuralPropertyPath(entityCollection.Name, items);
                    if (pathWithOrder.Value)
                    {
                        clause += " desc";
                    }
                    return(clause);
                }
                else
                {
                    throw new UnresolvableObjectException(items[0], $"Property path [{items[0]}] not found");
                }
            }
        }
 internal EntityCollection(string name, EntityCollection baseEntityCollection = null)
 {
     _name = name;
     _baseEntityCollection = baseEntityCollection;
 }
Пример #11
0
 public EntityCollection NavigateToCollection(EntityCollection rootCollection, string path)
 {
     return(NavigateToCollection(rootCollection, GetCollectionPathSegments(path)));
 }
Пример #12
0
        public EntityCollection GetDerivedEntityCollection(EntityCollection baseCollection, string entityTypeName)
        {
            var actualName = GetDerivedEntityTypeExactName(baseCollection.Name, entityTypeName);

            return(new EntityCollection(actualName, baseCollection));
        }