bool CheckReadOnlyAttribute() { ReadOnlyAttribute attr = null; MetaModel.GetDataFieldAttribute <ReadOnlyAttribute> (Attributes, ref attr); // Apparently attr.IsReadOnly and/or comparisons to // ReadOnlyAttribute.{Yes,No} don't matter. The sole presence of the // attribute marks column as read-only return(attr != null); }
DisplayFormatAttribute GetDisplayFormat() { MetaModel.GetDataFieldAttribute <DisplayFormatAttribute> (Attributes, ref displayFormatAttr); if (displayFormatAttr == null) { var dta = DataTypeAttribute; displayFormatAttr = dta == null ? null : dta.DisplayFormat; } return(displayFormatAttr); }
RequiredAttribute CheckRequiredAttribute() { if (requiredReflected) { return(requiredAttr); } requiredReflected = true; MetaModel.GetDataFieldAttribute <RequiredAttribute> (Attributes, ref requiredAttr); return(requiredAttr); }
bool DetermineSortDescending() { DisplayColumnAttribute attr = null; MetaModel.GetDataFieldAttribute <DisplayColumnAttribute> (Attributes, ref attr); if (attr == null) { return(false); } return(attr.SortDescending); }
string CheckDisplayName() { DisplayNameAttribute attr = null; MetaModel.GetDataFieldAttribute <DisplayNameAttribute> (Attributes, ref attr); if (attr != null) { return(attr.DisplayName); } return(Name); }
int CheckMaxLength() { StringLengthAttribute attr = null; MetaModel.GetDataFieldAttribute <StringLengthAttribute> (Attributes, ref attr); if (attr != null) { return(attr.MaximumLength); } return(Provider.MaxLength); }
DescriptionAttribute CheckDescriptionAttribute() { descriptionReflected = true; DescriptionAttribute dummy = null; MetaModel.GetDataFieldAttribute <DescriptionAttribute> (Attributes, ref dummy); if (dummy == null) { return(null); } return(dummy); }
DefaultValueAttribute CheckDefaultValueAttribute() { defaultValueReflected = true; DefaultValueAttribute dummy = null; MetaModel.GetDataFieldAttribute <DefaultValueAttribute> (Attributes, ref dummy); if (dummy == null) { return(null); } return(dummy); }
DataTypeAttribute CheckDataTypeAttribute() { if (dataTypeReflected) { return(dataTypeAttr); } dataTypeReflected = true; MetaModel.GetDataFieldAttribute <DataTypeAttribute> (Attributes, ref dataTypeAttr); if (dataTypeAttr == null && (ColumnType == typeof(string))) { return(new DataTypeAttribute(IsLongString ? DataType.MultilineText : DataType.Text)); } return(dataTypeAttr); }
string CheckUIHintAttribute() { if (uiHintReflected) { return(uiHint); } uiHintReflected = true; UIHintAttribute attr = null; MetaModel.GetDataFieldAttribute <UIHintAttribute> (Attributes, ref attr); if (attr == null) { return(null); } return(attr.UIHint); }
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. }