Exemplo n.º 1
0
        public DynamicDependentPropertyInfo GetDependentProperties(String tableEdmName, String navigationPropertyName)
        {
            IReadOnlyList <Navigation> navigations = _schemaCache.GetNavigations(tableEdmName);

            if (navigations.Count > 0)
            {
                foreach (Navigation navigation in navigations)
                {
                    if (navigation.NavigationName == navigationPropertyName)
                    {
                        IReadOnlyList <KeyColumnUsage> dependent = _schemaCache.GetKeyColumns(navigation.ConstraintSchema, navigation.DependentConstraintName);
                        IReadOnlyList <KeyColumnUsage> principal = _schemaCache.GetKeyColumns(navigation.ConstraintSchema, navigation.PrincipalConstraintName);
                        var principalPropertyNames = new List <String>(principal.Select(p => p.ColumnName));
                        var dependentPropertyNames = new List <String>(dependent.Select(p => p.ColumnName));

                        String?principalEdmName = _schemaCache.GetTableEdmName(principal[0].TableSchema, principal[0].TableName);
                        if (principalEdmName == null)
                        {
                            throw new InvalidOperationException($"Table {principal[0].TableSchema}.{principal[0].TableName} not found");
                        }

                        String?dependentEdmName = _schemaCache.GetTableEdmName(dependent[0].TableSchema, dependent[0].TableName);
                        if (dependentEdmName == null)
                        {
                            throw new InvalidOperationException($"Table {dependent[0].TableSchema}.{dependent[0].TableName} not found");
                        }

                        return(new DynamicDependentPropertyInfo(principalEdmName, dependentEdmName, principalPropertyNames, dependentPropertyNames, navigation.IsCollection));
                    }
                }
            }

            throw new InvalidOperationException("Navigation property " + navigationPropertyName + " not found in table " + tableEdmName);
        }
 public DynamicDependentPropertyInfo GetDependentProperties(String tableName, String navigationPropertyName)
 {
     (String tableSchema, String tableName, bool isQueryType)tableFullName = _schemaCache.GetTables()[tableName];
     if (_schemaCache.GetNavigations().TryGetValue((tableFullName.tableSchema, tableFullName.tableName), out List <SchemaCache.Navigation> navigations))
     {
         foreach (SchemaCache.Navigation navigation in navigations)
         {
             if (navigation.NavigationName == navigationPropertyName)
             {
                 IReadOnlyList <KeyColumnUsage> dependent = _schemaCache.GetKeyColumns()[(navigation.ConstraintSchema, navigation.DependentConstraintName)];