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); }
internal string Format(ODataClientWithCommand client, Table table) { return this.Format(new ExpressionContext() { Client = client, Table = table }); }
internal string Format(ISchema schema, Table table) { return this.Format(new ExpressionContext() { Schema = schema, Table = table }); }
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(); }
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(); }
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); }
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); }
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); }
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; }
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; }
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); } }
public PropertyDataItem(ServiceInfo service, Table table, Column column) : base(GetUniqueId(service.Name, table.ActualName, column.ActualName), column.ActualName, GetColumnSummary(column, table.GetKeyNames()), null, null) { }
public PropertyDataItem(ServiceInfo service, Table table, Association association) : base(GetUniqueId(service.Name, table.ActualName, association.ActualName), association.ActualName, GetAssociationSummary(association), null, null) { }
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); }
private string FormatWhereClause(Table table, QueryCommand cmd) { if (cmd.Criteria != null) { return FormatFilter(_expressionFormatter.Format(cmd.Criteria)); } return null; }
private string FormatSelectItem(Table table, SimpleReference item) { return table.FindColumn(item.GetAliasOrName()).ActualName; }
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; }
private string FormatTakeClause(Table table, QueryCommand cmd) { if (cmd.TakeCount > 0) { return "$top=" + cmd.TakeCount.ToString(); } return null; }
private EntryMembers ParseEntryMembers(Table table, IDictionary<string, object> entryData) { var entryMembers = new EntryMembers(); foreach (var item in entryData) { ParseEntryMember(table, item, entryMembers); } return entryMembers; }
private string FormatSkipClause(Table table, QueryCommand cmd) { if (cmd.SkipCount > 0) { return "$skip=" + cmd.SkipCount.ToString(); } return null; }
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; }
private string FormatWithClause(Table table, QueryCommand cmd) { if (cmd.Expand.Any()) { var expansion = string.Join(",", cmd.Expand); return "$expand=" + expansion; } return null; }
private static string GetCollectionSummary(Table table) { return string.Format("{0} properties, {1} relations", table.Columns.Count(), table.Associations.Count()); }
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; }
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); }
public ValueParser(Table table) { _table = table; }
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; }
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; }
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)); } }
private string FormatCountClause(Table table, QueryCommand cmd) { if (cmd.SetTotalCount != null) { return "$inlinecount=allpages"; } return null; }