コード例 #1
0
        internal IDictionary <string, object> GetColumnValuesFromRoute(HttpContextBase context)
        {
            RouteValueDictionary        routeValues  = DynamicDataRouteHandler.GetRequestContext(context).RouteData.Values;
            Dictionary <string, object> columnValues = new Dictionary <string, object>();

            foreach (var column in Columns)
            {
                if (Misc.IsColumnInDictionary(column, routeValues))
                {
                    MetaForeignKeyColumn foreignKeyColumn = column as MetaForeignKeyColumn;
                    if (foreignKeyColumn != null)
                    {
                        // Add all the foreign keys to the column values.
                        foreach (var fkName in foreignKeyColumn.ForeignKeyNames)
                        {
                            columnValues[fkName] = routeValues[fkName];
                        }
                    }
                    else
                    {
                        // Convert the value to the correct type.
                        columnValues[column.Name] = Misc.ChangeType(routeValues[column.Name], column.ColumnType);
                    }
                }
            }
            return(columnValues);
        }
コード例 #2
0
ファイル: ForeignKeyManager.cs プロジェクト: weavver/data
        //-------------------------------------------------------------------------------------------
        public static void PopulateListControl(MetaForeignKeyColumn Column,
            DropDownList listControl,
            Guid orgId)
        {
            //var filterAttribute = Column.GetAttribute<FilterForeignKeyAttribute>();
               //if (filterAttribute == null || Session[filterAttribute.SessionVariableName] == null)
               //{
               //     base.PopulateListControl(listControl);
               //     return;
               //}

               var context = Column.Table.CreateContext(); // get context;
               var foreignKeyTable = Column.ParentTable; // get fkTable
               var filterColumn = foreignKeyTable.GetColumn("OrganizationId"); // get filter column
               var value = orgId; //Convert.ChangeType(, filterColumn.TypeCode, System.Globalization.CultureInfo.InvariantCulture); // get value
               var query = foreignKeyTable.GetQuery(context); // Get Column Value query
               var entityParam = Expression.Parameter(foreignKeyTable.EntityType, foreignKeyTable.Name); // get the table entity to be filtered
               var property = Expression.Property(entityParam, filterColumn.Name); // get the property to be filtered
               var equalsCall = Expression.Equal(property, Expression.Constant(value)); // get the equal call
               var whereLambda = Expression.Lambda(equalsCall, entityParam); // get the where lambda
               var whereCall = Expression.Call(typeof(Queryable), "Where", new Type[] { foreignKeyTable.EntityType }, query.Expression, whereLambda); // get the where call
               var values = query.Provider.CreateQuery(whereCall);
               foreach (var row in values)
               {
                    listControl.Items.Add(new ListItem()
                    {
                         Text = foreignKeyTable.GetDisplayString(row),
                         Value = foreignKeyTable.GetPrimaryKeyString(row)
                    });
               }
        }
コード例 #3
0
        private void Page_InitComplete(object sender, EventArgs e)
        {
            if (!Owner.Page.IsPostBack)
            {
                // Do not reconfigure the Expression on postback. It's values should be preserved via ViewState.
                Control   control = FindTargetControl();
                MetaTable table   = DataSource.GetMetaTable();

                if (String.IsNullOrEmpty(Column))
                {
                    foreach (var param in GetPrimaryKeyControlParameters(control, table))
                    {
                        Expression.Parameters.Add(param);
                    }
                }
                else
                {
                    MetaForeignKeyColumn column = (MetaForeignKeyColumn)table.GetColumn(Column);
                    foreach (var param in GetForeignKeyControlParameters(control, column))
                    {
                        Expression.Parameters.Add(param);
                    }
                }
            }

            Expression.SetContext(Owner, Context, DataSource);
        }
コード例 #4
0
        private static Dictionary <string, MetaColumn> CreateColumnMapping(MetaForeignKeyColumn column, IList <MetaColumn> columns)
        {
            var names = column.ForeignKeyNames;

            Debug.Assert(names.Count == columns.Count);
            Dictionary <string, MetaColumn> nameColumnMapping = new Dictionary <string, MetaColumn>();

            for (int i = 0; i < names.Count; i++)
            {
                // Get the filter expression for this foreign key name
                string filterExpression = column.GetFilterExpression(names[i]);
                nameColumnMapping[filterExpression] = columns[i];
            }
            return(nameColumnMapping);
        }
コード例 #5
0
        private void ClearDefaultValues()
        {
            IDictionary <string, object> defaultValues = DefaultValues;

            if (defaultValues != null)
            {
                MetaForeignKeyColumn foreignKeyColumn = Column as MetaForeignKeyColumn;
                if (foreignKeyColumn != null)
                {
                    foreach (var fkName in foreignKeyColumn.ForeignKeyNames)
                    {
                        defaultValues.Remove(fkName);
                    }
                }
                else
                {
                    defaultValues.Remove(Column.Name);
                }
            }
        }
コード例 #6
0
        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;
                }
            }
        }
コード例 #7
0
ファイル: MetaTable.cs プロジェクト: pmq20/mono_forked
        internal MetaTable(MetaModel model, TableProvider provider, ContextConfiguration configuration)
        {
            bool scaffoldAllTables;

            this.model = model;
            Provider   = provider;
            if (configuration != null)
            {
                ScaffoldAllTables = scaffoldAllTables = configuration.ScaffoldAllTables;
                Func <Type, TypeDescriptionProvider> factory = configuration.MetadataProviderFactory;
                if (factory != null)
                {
                    Type t = EntityType;
                    TypeDescriptionProvider p = factory(t);
                    if (p != null)
                    {
                        TypeDescriptor.AddProvider(p, t);
                    }
                }
            }
            else
            {
                scaffoldAllTables = false;
            }

            ScaffoldTableAttribute attr = null;

            MetaModel.GetDataFieldAttribute <ScaffoldTableAttribute> (Attributes, ref attr);
            Scaffold        = attr != null ? attr.Scaffold : scaffoldAllTables;
            DataContextType = provider.DataModel.ContextType;

            var        columns               = new List <MetaColumn> ();
            var        primaryKeyColumns     = new List <MetaColumn> ();
            var        foreignKeyColumnNames = new List <string> ();
            MetaColumn mc;

            foreach (var c in provider.Columns)
            {
                // this seems to be the determining factor on whether we create
                // MetaColumn or MetaForeignKeyColumn/MetaChildrenColumn. As the
                // determination depends upon the relationship direction, we must
                // check that using the ColumnProvider's association, if any.
                //
                //  http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metaforeignkeycolumn.aspx
                //  http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metachildrencolumn.aspx
                //  http://forums.asp.net/t/1426992.aspx
                var association = c.Association;
                if (association == null)
                {
                    mc = new MetaColumn(this, c);
                }
                else
                {
                    var dir = association.Direction;
                    if (dir == AssociationDirection.OneToOne || dir == AssociationDirection.ManyToOne)
                    {
                        mc = new MetaForeignKeyColumn(this, c);
                    }
                    else
                    {
                        mc = new MetaChildrenColumn(this, c);
                    }
                }

                columns.Add(mc);
                if (c.IsPrimaryKey)
                {
                    primaryKeyColumns.Add(mc);
                }

                if (mc is MetaForeignKeyColumn)
                {
                    foreignKeyColumnNames.Add(c.Name);
                }
            }

            Columns           = new ReadOnlyCollection <MetaColumn> (columns);
            PrimaryKeyColumns = new ReadOnlyCollection <MetaColumn> (primaryKeyColumns);
            if (foreignKeyColumnNames.Count == 0)
            {
                ForeignKeyColumnsNames = String.Empty;
            }
            else
            {
                ForeignKeyColumnsNames = String.Join(",", foreignKeyColumnNames.ToArray());
            }

            HasPrimaryKey = primaryKeyColumns.Count > 0;

            // See http://forums.asp.net/t/1388561.aspx
            //
            // Also, http://forums.asp.net/t/1307243.aspx - that seems to be out of
            // scope for us, though (at least for now)
            IsReadOnly = primaryKeyColumns.Count == 0;

            // FIXME: fill more properties.
        }
コード例 #8
0
ファイル: MetaTable.cs プロジェクト: nobled/mono
		internal MetaTable (MetaModel model, TableProvider provider, ContextConfiguration configuration)
		{
			bool scaffoldAllTables;
			
			this.model = model;
			Provider = provider;
			if (configuration != null) {
				ScaffoldAllTables = scaffoldAllTables = configuration.ScaffoldAllTables;
				Func <Type, TypeDescriptionProvider> factory = configuration.MetadataProviderFactory;
				if (factory != null) {
					Type t = EntityType;
					TypeDescriptionProvider p = factory (t);
					if (p != null)
						TypeDescriptor.AddProvider (p, t);
				}
			} else
				scaffoldAllTables = false;
			
			ScaffoldTableAttribute attr = null;
			MetaModel.GetDataFieldAttribute <ScaffoldTableAttribute> (Attributes, ref attr);
			Scaffold = attr != null ? attr.Scaffold : scaffoldAllTables;
			DataContextType = provider.DataModel.ContextType;
			
			var columns = new List <MetaColumn> ();
			var primaryKeyColumns = new List <MetaColumn> ();
			var foreignKeyColumnNames = new List <string> ();
			MetaColumn mc;
			
			foreach (var c in provider.Columns) {
				// this seems to be the determining factor on whether we create
				// MetaColumn or MetaForeignKeyColumn/MetaChildrenColumn. As the
				// determination depends upon the relationship direction, we must
				// check that using the ColumnProvider's association, if any.
				//
				//  http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metaforeignkeycolumn.aspx
				//  http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.metachildrencolumn.aspx
				//  http://forums.asp.net/t/1426992.aspx
				var association = c.Association;
				if (association == null)
					mc = new MetaColumn (this, c);
				else {
					var dir = association.Direction;
					if (dir == AssociationDirection.OneToOne || dir == AssociationDirection.ManyToOne)
						mc = new MetaForeignKeyColumn (this, c);
					else
						mc = new MetaChildrenColumn (this, c);
				}
				
				columns.Add (mc);
				if (c.IsPrimaryKey)
					primaryKeyColumns.Add (mc);

				if (mc is MetaForeignKeyColumn)
					foreignKeyColumnNames.Add (c.Name);
			}
			
			Columns = new ReadOnlyCollection <MetaColumn> (columns);
			PrimaryKeyColumns = new ReadOnlyCollection <MetaColumn> (primaryKeyColumns);
			if (foreignKeyColumnNames.Count == 0)
				ForeignKeyColumnsNames = String.Empty;
			else
				ForeignKeyColumnsNames = String.Join (",", foreignKeyColumnNames.ToArray ());
			
			HasPrimaryKey = primaryKeyColumns.Count > 0;

			// See http://forums.asp.net/t/1388561.aspx
			//
			// Also, http://forums.asp.net/t/1307243.aspx - that seems to be out of
			// scope for us, though (at least for now)
			IsReadOnly = primaryKeyColumns.Count == 0;
			
			// FIXME: fill more properties.
		}
コード例 #9
0
        private IEnumerable <Parameter> GetForeignKeyControlParameters(Control control, MetaForeignKeyColumn column)
        {
            // For each underlying FK, we need to create a ControlParameter
            MetaTable otherTable = column.ParentTable;
            Dictionary <string, MetaColumn> nameColumnMapping = CreateColumnMapping(column, otherTable.PrimaryKeyColumns);

            return(GetControlParameters(control, nameColumnMapping));
        }
コード例 #10
0
 private static Dictionary<string, MetaColumn> CreateColumnMapping(MetaForeignKeyColumn column, IList<MetaColumn> columns) {
     var names = column.ForeignKeyNames;
     Debug.Assert(names.Count == columns.Count);
     Dictionary<string, MetaColumn> nameColumnMapping = new Dictionary<string, MetaColumn>();
     for (int i = 0; i < names.Count; i++) {
         // Get the filter expression for this foreign key name
         string filterExpression = column.GetFilterExpression(names[i]);
         nameColumnMapping[filterExpression] = columns[i];
     }
     return nameColumnMapping;
 }
コード例 #11
0
 private IEnumerable<Parameter> GetForeignKeyControlParameters(Control control, MetaForeignKeyColumn column) {
     // For each underlying FK, we need to create a ControlParameter
     MetaTable otherTable = column.ParentTable;
     Dictionary<string, MetaColumn> nameColumnMapping = CreateColumnMapping(column, otherTable.PrimaryKeyColumns);
     return GetControlParameters(control, nameColumnMapping);
 }
コード例 #12
0
        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);
                }
            }
        }