Example #1
0
        private void BindToDataItem(object dataItem)
        {
            dataItem = Misc.GetRealDataItem(dataItem);
            Debug.Assert(dataItem != null, "DataItem is null");
            // Try to get the MetaTable from the type and if we can't find it then ---- up.
            MetaTable table = Misc.GetTableFromTypeHierarchy(dataItem.GetType());

            if (table == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture,
                                                        DynamicDataResources.MetaModel_EntityTypeDoesNotBelongToModel,
                                                        dataItem.GetType().FullName));
            }

            string action = GetActionOrDefaultTo(PageAction.Details);

            NavigateUrl = table.GetActionPath(action, GetRouteValues(table, dataItem));

            if (String.IsNullOrEmpty(Text))
            {
                if (!String.IsNullOrEmpty(DataField))
                {
                    Text = DataBinder.GetPropertyValue(dataItem, DataField).ToString();
                }
                else
                {
                    Text = table.GetDisplayString(dataItem);
                }
            }
        }
Example #2
0
        internal MetaTable GetForeignKeyMetaTable(object row)
        {
            // Get the foreign key reference
            object foreignKeyReference = DataBinder.GetPropertyValue(row, Name);

            // if the type is different to the parent table type then proceed to get the correct table
            if (foreignKeyReference != null)
            {
                // Get the correct MetaTable based on the live object. This is used for inheritance scenarios where the type of the navigation
                // property's parent table is some base type but the instance is pointing to a derived type.
                Type      rowType  = foreignKeyReference.GetType();
                MetaTable rowTable = Misc.GetTableFromTypeHierarchy(rowType);
                if (rowTable != null)
                {
                    return(rowTable);
                }
            }
            return(ParentTable);
        }