internal static IEnumerable <Parameter> GetControlParameters(Control control, IDictionary <string, MetaColumn> nameColumnMapping)
        {
            IControlParameterTarget target = null;

            target = DynamicDataManager.GetControlParameterTarget(control);
            Debug.Assert(target != null);

            foreach (var entry in nameColumnMapping)
            {
                string     parameterName = entry.Key;
                MetaColumn column        = entry.Value;

                ControlParameter controlParameter = new ControlParameter()
                {
                    Name      = parameterName,
                    ControlID = control.UniqueID
                };
                if (target != null)
                {
                    // this means the relationship consists of more than one key and we need to expand the property name
                    controlParameter.PropertyName = target.GetPropertyNameExpression(column.Name);
                }
                DataSourceUtil.SetParameterTypeCodeAndDbType(controlParameter, column);
                yield return(controlParameter);
            }
        }
        private IEnumerable <Parameter> GetPropertyControlWhereParameters(Control control,
                                                                          IControlParameterTarget paramTarget, MetaColumn column)
        {
            ControlParameter controlParameter = new ControlParameter()
            {
                Name         = column.Name,
                ControlID    = control.UniqueID,
                PropertyName = paramTarget.GetPropertyNameExpression(column.Name)
            };

            DataSourceUtil.SetParameterTypeCodeAndDbType(controlParameter, column);

            yield return(controlParameter);
        }
        private IEnumerable <Parameter> GetPrimaryKeyControlWhereParameters(Control control,
                                                                            IControlParameterTarget paramTarget)
        {
            MetaTable parentTable = paramTarget.Table;

            if (parentTable != null)
            {
                // For each PK column in the table, we need to create a ControlParameter
                foreach (var keyColumn in parentTable.PrimaryKeyColumns)
                {
                    var controlParameter = new ControlParameter()
                    {
                        Name         = keyColumn.Name,
                        ControlID    = control.UniqueID,
                        PropertyName = paramTarget.GetPropertyNameExpression(keyColumn.Name)
                    };

                    DataSourceUtil.SetParameterTypeCodeAndDbType(controlParameter, keyColumn);

                    yield return(controlParameter);
                }
            }
        }
        private IEnumerable <Parameter> GetForeignKeyControlWhereParameters(Control control,
                                                                            IControlParameterTarget paramTarget, MetaForeignKeyColumn column)
        {
            MetaTable parentTable = paramTarget.Table;

            if (parentTable != null)
            {
                string namePrefix = String.Empty;
                // Make sure the data types match
                if (column.ColumnType != parentTable.EntityType)
                {
                    throw new Exception(String.Format(CultureInfo.CurrentCulture,
                                                      DynamicDataResources.DynamicControlParameter_DynamicDataSourceColumnNotCompatibleWithTable,
                                                      column.DisplayName, parentTable.Name));
                }

                // For each underlying FK, we need to create a ControlParameter
                Debug.Assert(column.ForeignKeyNames.Count == parentTable.PrimaryKeyColumns.Count);
                int index = 0;
                foreach (var fkName in column.ForeignKeyNames)
                {
                    MetaColumn parentTablePKColumn = parentTable.PrimaryKeyColumns[index++];

                    var controlParameter = new ControlParameter()
                    {
                        Name         = fkName,
                        ControlID    = control.UniqueID,
                        PropertyName = paramTarget.GetPropertyNameExpression(parentTablePKColumn.Name)
                    };

                    DataSourceUtil.SetParameterTypeCodeAndDbType(controlParameter, parentTablePKColumn);

                    yield return(controlParameter);
                }
            }
        }