コード例 #1
0
 public IEnumerable<Association> GetAssociations(Table table)
 {
     var principals = from e in _schema.Metadata.EntityContainers
                      //where e.IsDefaulEntityContainer
                      from s in e.AssociationSets
                      where s.End.First().EntitySet == table.ActualName
                      from a in _schema.Metadata.Associations
                      where s.Association == GetQualifiedName(_schema.Metadata.TypesNamespace, a.Name)
                      from n in a.End
                      where n.Role == s.End.Last().Role
                      from t in GetEntityTypeWithBaseTypes(table.EntityType)
                      from np in t.NavigationProperties
                      where np.Relationship == GetQualifiedName(_schema.Metadata.TypesNamespace, a.Name) && np.ToRole == n.Role
                      select CreateAssociation(np.Name, s.End.Last(), n);
     var dependents = from e in _schema.Metadata.EntityContainers
                      //where e.IsDefaulEntityContainer
                      from s in e.AssociationSets
                      where s.End.Last().EntitySet == table.ActualName
                      from a in _schema.Metadata.Associations
                      where s.Association == GetQualifiedName(_schema.Metadata.TypesNamespace, a.Name)
                      from n in a.End
                      where n.Role == s.End.First().Role
                      from t in GetEntityTypeWithBaseTypes(table.EntityType)
                      from np in t.NavigationProperties
                      where np.Relationship == GetQualifiedName(_schema.Metadata.TypesNamespace, a.Name) && np.ToRole == n.Role
                      select CreateAssociation(np.Name, s.End.First(), n);
     return principals.Union(dependents);
 }
コード例 #2
0
 internal string Format(ODataClientWithCommand client, Table table)
 {
     return this.Format(new ExpressionContext()
                            {
                                Client = client, 
                                Table = table
                            });
 }
コード例 #3
0
 internal string Format(ISchema schema, Table table)
 {
     return this.Format(new ExpressionContext()
                            {
                                Schema = schema, 
                                Table = table
                            });
 }
コード例 #4
0
 public Key GetPrimaryKey(Table table)
 {
     return (from s in GetEntitySets()
             where s.Name == table.ActualName
             from et in GetEntitySetType(s)
             from t in GetEntityTypeWithBaseTypes(et)
             where t.Key != null
             select new Key(t.Key.Properties)).SingleOrDefault();
 }
コード例 #5
0
ファイル: SchemaProvider.cs プロジェクト: larsw/Simple.OData
 public Key GetPrimaryKey(Table table)
 {
     return (from e in _metadata.Value.EntityContainers
             where e.IsDefaulEntityContainer
             from s in e.EntitySets
             where s.Name == table.ActualName
             from t in _metadata.Value.EntityTypes
             where s.EntityType.Split('.').Last() == t.Name
             select new Key(t.Key.Properties)).Single();
 }
コード例 #6
0
ファイル: Table.cs プロジェクト: nanohex/Simple.OData.Client
 internal Table(string name, EdmEntityType entityType, Table baseTable, Schema schema)
 {
     _actualName = name;
     _entityType = entityType;
     _baseTable = baseTable;
     _schema = schema;
     _lazyDerivedTables = new Lazy<TableCollection>(GetDerivedTables);
     _lazyColumns = new Lazy<ColumnCollection>(GetColumns);
     _lazyAssociations = new Lazy<AssociationCollection>(GetAssociations);
     _lazyPrimaryKey = new Lazy<Key>(GetPrimaryKey);
 }
コード例 #7
0
 public IEnumerable<Column> GetColumns(Table table)
 {
     return from e in _metadata.Value.EntityContainers
            where e.IsDefaulEntityContainer
            from s in e.EntitySets
            where s.Name == table.ActualName
            from t in _metadata.Value.EntityTypes
            where s.EntityType.Split('.').Last() == t.Name
            from p in t.Properties
            select new Column(p.Name, p.Type, p.Nullable);
 }
コード例 #8
0
 public IEnumerable<Association> GetAssociations(Table table)
 {
     var principals = from e in _metadata.Value.EntityContainers
                      where e.IsDefaulEntityContainer
                      from s in e.AssociationSets
                      where s.End.First().EntitySet == table.ActualName
                      from a in _metadata.Value.Associations
                      where s.Association == GetQualifiedName(_metadata.Value.TypesNamespace, a.Name)
                      from n in a.End
                      where n.Role == s.End.Last().Role
                      select CreateAssociation(s.End.Last(), n);
     var dependents = from e in _metadata.Value.EntityContainers
                      where e.IsDefaulEntityContainer
                      from s in e.AssociationSets
                      where s.End.Last().EntitySet == table.ActualName
                      from a in _metadata.Value.Associations
                      where s.Association == GetQualifiedName(_metadata.Value.TypesNamespace, a.Name)
                      from n in a.End
                      where n.Role == s.End.First().Role
                      select CreateAssociation(s.End.First(), n);
     return principals.Union(dependents);
 }
コード例 #9
0
ファイル: ResultDataItem.cs プロジェクト: object/ODataPad
 public ResultDataItem(IDictionary<string, object> results, Table table)
     : base(Guid.NewGuid().ToString(), GetKeySummary(results, table.GetKeyNames()), GetResultSummary(results, table.GetKeyNames()), null, null)
 {
     this.Keys = table.GetKeyNames();
     this.Results = results;
 }
コード例 #10
0
ファイル: DataSource.cs プロジェクト: object/ODataPad
 private CollectionDataItem CreateCollectionDataItem(ServiceInfo service, Table table)
 {
     var item = new CollectionDataItem(service, table);
     foreach (var column in table.Columns)
     {
         item.Elements.Add(new PropertyDataItem(service, table, column));
     }
     foreach (var association in table.Associations)
     {
         item.Elements.Add(new PropertyDataItem(service, table, association));
     }
     return item;
 }
コード例 #11
0
        private IEnumerable<string> BuildReferencePath(List<string> pathNames, Table table, List<string> elementNames, ExpressionContext context)
        {
            if (!elementNames.Any())
            {
                return pathNames;
            }

            var objectName = elementNames.First();
            if (table != null)
            {
                if (table.HasColumn(objectName))
                {
                    pathNames.Add(table.FindColumn(objectName).ActualName);
                    return BuildReferencePath(pathNames, null, elementNames.Skip(1).ToList(), context);
                }
                else if (table.HasAssociation(objectName))
                {
                    var association = table.FindAssociation(objectName);
                    pathNames.Add(association.ActualName);
                    return BuildReferencePath(pathNames, context.Schema.FindTable(association.ReferenceTableName), elementNames.Skip(1).ToList(), context);
                }
                else
                {
                    var formattedFunction = FormatAsFunction(objectName, context);
                    if (!string.IsNullOrEmpty(formattedFunction))
                    {
                        pathNames.Add(formattedFunction);
                        return BuildReferencePath(pathNames, null, elementNames.Skip(1).ToList(), context);
                    }
                    else
                    {
                        throw new UnresolvableObjectException(objectName, string.Format("Invalid referenced object {0}", objectName));
                    }
                }
            }
            else if (FunctionMapping.SupportedFunctions.ContainsKey(new ExpressionFunction.FunctionCall(elementNames.First(), 0)))
            {
                var formattedFunction = FormatAsFunction(objectName, context);
                pathNames.Add(formattedFunction);
                return BuildReferencePath(pathNames, null, elementNames.Skip(1).ToList(), context);
            }
            else
            {
                pathNames.AddRange(elementNames);
                return BuildReferencePath(pathNames, null, new List<string>(), context);
            }
        }
コード例 #12
0
ファイル: PropertyDataItem.cs プロジェクト: object/ODataPad
 public PropertyDataItem(ServiceInfo service, Table table, Column column)
     : base(GetUniqueId(service.Name, table.ActualName, column.ActualName), column.ActualName, GetColumnSummary(column, table.GetKeyNames()), null, null)
 {
 }
コード例 #13
0
ファイル: PropertyDataItem.cs プロジェクト: object/ODataPad
 public PropertyDataItem(ServiceInfo service, Table table, Association association)
     : base(GetUniqueId(service.Name, table.ActualName, association.ActualName), association.ActualName, GetAssociationSummary(association), null, null)
 {
 }
コード例 #14
0
 public IEnumerable<Column> GetColumns(Table table)
 {
     return from t in GetEntityTypeWithBaseTypes(table.EntityType)
            from p in t.Properties
            select new Column(p.Name, p.Type, p.Nullable);
 }
コード例 #15
0
 private string FormatWhereClause(Table table, QueryCommand cmd)
 {
     if (cmd.Criteria != null)
     {
         return FormatFilter(_expressionFormatter.Format(cmd.Criteria));
     }
     return null;
 }
コード例 #16
0
 private string FormatSelectItem(Table table, SimpleReference item)
 {
     return table.FindColumn(item.GetAliasOrName()).ActualName;
 }
コード例 #17
0
 private string FormatOrderByItem(Table table, SimpleOrderByItem item)
 {
     var col = table.FindColumn(item.Reference.GetName());
     var direction = item.Direction == OrderByDirection.Descending ? " desc" : string.Empty;
     return col.ActualName + direction;
 }
コード例 #18
0
 private string FormatTakeClause(Table table, QueryCommand cmd)
 {
     if (cmd.TakeCount > 0)
     {
         return "$top=" + cmd.TakeCount.ToString();
     }
     return null;
 }
コード例 #19
0
        private EntryMembers ParseEntryMembers(Table table, IDictionary<string, object> entryData)
        {
            var entryMembers = new EntryMembers();

            foreach (var item in entryData)
            {
                ParseEntryMember(table, item, entryMembers);
            }

            return entryMembers;
        }
コード例 #20
0
 private string FormatSkipClause(Table table, QueryCommand cmd)
 {
     if (cmd.SkipCount > 0)
     {
         return "$skip=" + cmd.SkipCount.ToString();
     }
     return null;
 }
コード例 #21
0
 private string FormatOrderClause(Table table, QueryCommand cmd)
 {
     if (cmd.Order.Any())
     {
         var items = cmd.Order.Select(x => FormatOrderByItem(table, x));
         return "$orderby=" + string.Join(",", items);
     }
     return null;
 }
コード例 #22
0
 private string FormatWithClause(Table table, QueryCommand cmd)
 {
     if (cmd.Expand.Any())
     {
         var expansion = string.Join(",", cmd.Expand);
         return "$expand=" + expansion;
     }
     return null;
 }
コード例 #23
0
ファイル: CollectionDataItem.cs プロジェクト: object/ODataPad
 private static string GetCollectionSummary(Table table)
 {
     return string.Format("{0} properties, {1} relations", table.Columns.Count(), table.Associations.Count());
 }
コード例 #24
0
 private string FormatTableClause(string tablePath, string formattedKeyValues, out Table table)
 {
     string clause = string.Empty;
     var tableNames = ExtractTableNames(tablePath);
     table = null;
     if (tableNames.Count() > 1)
     {
         Table parentTable = null;
         foreach (var tableName in tableNames)
         {
             if (parentTable == null)
             {
                 var childTable = _findTable(tableName);
                 table = childTable;
                 clause += childTable.ActualName;
                 if (!string.IsNullOrEmpty(formattedKeyValues))
                     clause += formattedKeyValues;
                 parentTable = childTable;
             }
             else
             {
                 var association = parentTable.FindAssociation(tableName);
                 parentTable = _findTable(association.ReferenceTableName);
                 clause += "/" + association.ActualName;
             }
         }
     }
     else
     {
         table = _findTable(tablePath);
         clause = table.ActualName;
         if (!string.IsNullOrEmpty(formattedKeyValues))
             clause += formattedKeyValues;
     }
     return clause;
 }
コード例 #25
0
 public IEnumerable<Table> GetDerivedTables(Table table)
 {
     return from et in _metadata.Value.EntityTypes
            where et.BaseType != null && et.BaseType.Name == table.EntityType.Name 
            select new Table(et.Name, et, table, _schema.Value);
 }
コード例 #26
0
 public ValueParser(Table table)
 {
     _table = table;
 }
コード例 #27
0
 private string FormatSelectClause(Table table, QueryCommand cmd)
 {
     if (cmd.Columns != null && cmd.Columns.Count() > 0)
     {
         var items = cmd.Columns.Select(x => FormatSelectItem(table, x));
         return "$select=" + string.Join(",", items);
     }
     return null;
 }
コード例 #28
0
 private string FormatSpecialClause(Table table, QueryCommand cmd)
 {
     if (cmd.Columns != null && cmd.Columns.Count() == 1 && cmd.Columns.First() is SpecialReference)
     {
         var specialColumn = cmd.Columns.First();
         cmd.Columns.Clear();
         return FormatSpecialReference((SpecialReference)specialColumn);
     }
     return null;
 }
コード例 #29
0
 private void ParseEntryMember(Table table, KeyValuePair<string, object> item, EntryMembers entryMembers)
 {
     if (table.HasColumn(item.Key))
     {
         entryMembers.AddProperty(item.Key, item.Value);
     }
     else if (table.HasAssociation(item.Key))
     {
         var association = table.FindAssociation(item.Key);
         if (association.IsMultiple)
         {
             var collection = item.Value as IEnumerable<object>;
             if (collection != null)
             {
                 foreach (var element in collection)
                 {
                     AddEntryAssociation(entryMembers, item.Key, element);
                 }
             }
         }
         else
         {
             AddEntryAssociation(entryMembers, item.Key, item.Value);
         }
     }
     else
     {
         throw new UnresolvableObjectException(item.Key, string.Format("No property or association found for {0}.", item.Key));
     }
 }
コード例 #30
0
 private string FormatCountClause(Table table, QueryCommand cmd)
 {
     if (cmd.SetTotalCount != null)
     {
         return "$inlinecount=allpages";
     }
     return null;
 }