public void DefaultValues() { var ctx = new ContextConfiguration(); var func = ctx.MetadataProviderFactory; Assert.IsTrue(func != null, "#A1"); Assert.AreEqual(typeof (Func <Type, TypeDescriptionProvider>), func.GetType (), "#A2"); Assert.AreEqual(false, ctx.ScaffoldAllTables, "#A3"); Assert.AreEqual(typeof(AssociatedMetadataTypeTypeDescriptionProvider), func(typeof(string)).GetType (), "#A4"); }
private static void RegisterRoutes(RouteCollection routes) { var contextConfiguration = new ContextConfiguration { ScaffoldAllTables = Global.Context.ScaffoldAllTables }; if (Global.CanCreateDataContext()) { Global.MetaModel.RegisterContext(() => Global.CreateDataContext(Global.Context.DataContextAssemblyLocation), contextConfiguration); routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = Global.MetaModel }); } }
public static void RegisterRoutes(RouteCollection routes) { // IMPORTANT: DATA MODEL REGISTRATION // Uncomment this line to register an ADO.NET Entity Framework model for ASP.NET Dynamic Data. // Set ScaffoldAllTables = true only if you are sure that you want all tables in the // data model to support a scaffold (i.e. templates) view. To control scaffolding for // individual tables, create a partial class for the table and apply the // [ScaffoldTable(true)] attribute to the partial class. // Note: Make sure that you change "YourDataContextType" to the name of the data context // class in your application. // See http://go.microsoft.com/fwlink/?LinkId=257395 for more information on how to add and configure an Entity Data model to this project //DefaultModel.RegisterContext(typeof(ProoftedDbContext), new ContextConfiguration() { ScaffoldAllTables = true }); //LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock); //UserDbContext.Borrow(context => //{ context.UserProfiles.ToList(); }); var contextConfiguration = new ContextConfiguration() { ScaffoldAllTables = true }; var objectContextAdapter = (IObjectContextAdapter)new ProoftedDbContext(); MvcApplication.DefaultModel.RegisterContext(() => objectContextAdapter.ObjectContext, contextConfiguration); // The following statement supports separate-page mode, where the List, Detail, Insert, and // Update tasks are performed by using separate pages. To enable this mode, uncomment the following // route definition, and comment out the route definitions in the combined-page mode section that follows. routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = MvcApplication.DefaultModel }); // The following statements support combined-page mode, where the List, Detail, Insert, and // Update tasks are performed by using the same page. To enable this mode, uncomment the // following routes and comment out the route definition in the separate-page mode section above. //routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { // Action = PageAction.List, // ViewName = "ListDetails", // Model = DefaultModel //}); //routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { // Action = PageAction.Details, // ViewName = "ListDetails", // Model = DefaultModel //}); }
public static void RegisterRoutes(RouteCollection routes) { // IMPORTANT: DATA MODEL REGISTRATION // Uncomment this line to register an ADO.NET Entity Framework model for ASP.NET Dynamic Data. // Set ScaffoldAllTables = true only if you are sure that you want all tables in the // data model to support a scaffold (i.e. templates) view. To control scaffolding for // individual tables, create a partial class for the table and apply the // [ScaffoldTable(true)] attribute to the partial class. // Note: Make sure that you change "YourDataContextType" to the name of the data context // class in your application. var contextConfiguration = new ContextConfiguration() { ScaffoldAllTables = false }; DefaultModel.RegisterContext(typeof(MOC10267Entities), contextConfiguration); // The following statement supports separate-page mode, where the List, Detail, Insert, and // Update tasks are performed by using separate pages. To enable this mode, uncomment the following // route definition, and comment out the route definitions in the combined-page mode section that follows. routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }), Model = DefaultModel }); // The following statements support combined-page mode, where the List, Detail, Insert, and // Update tasks are performed by using the same page. To enable this mode, uncomment the // following routes and comment out the route definition in the separate-page mode section above. //routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { // Action = PageAction.List, // ViewName = "ListDetails", // Model = DefaultModel //}); //routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { // Action = PageAction.Details, // ViewName = "ListDetails", // Model = DefaultModel //}); }
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. }
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. }
public virtual void RegisterContext(DataModelProvider dataModelProvider, ContextConfiguration configuration) { if (dataModelProvider == null) { throw new ArgumentNullException("dataModelProvider"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (_registerGlobally) { CheckForRegistrationException(); } // check if context has already been registered if (_contextTypes.Contains(dataModelProvider.ContextType)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.MetaModel_ContextAlreadyRegistered, dataModelProvider.ContextType.FullName)); } try { IEnumerable <TableProvider> tableProviders = dataModelProvider.Tables; // create and validate model var tablesToInitialize = new List <MetaTable>(); foreach (TableProvider tableProvider in tableProviders) { RegisterMetadataTypeDescriptionProvider(tableProvider, configuration.MetadataProviderFactory); MetaTable table = CreateTable(tableProvider); table.CreateColumns(); var tableNameAttribute = tableProvider.Attributes.OfType <TableNameAttribute>().SingleOrDefault(); string nameOverride = tableNameAttribute != null ? tableNameAttribute.Name : null; table.SetScaffoldAndName(configuration.ScaffoldAllTables, nameOverride); CheckTableNameConflict(table, nameOverride, tablesToInitialize); tablesToInitialize.Add(table); } _contextTypes.Add(dataModelProvider.ContextType); if (_registerGlobally) { MetaModelManager.AddModel(dataModelProvider.ContextType, this); } foreach (MetaTable table in tablesToInitialize) { AddTable(table); } // perform initialization at the very end to ensure all references will be properly registered foreach (MetaTable table in tablesToInitialize) { table.Initialize(); } } catch (Exception e) { if (_registerGlobally) { s_registrationException = e; } throw; } }
//------------------------------------------------------------------------------------------- public static void RegisterDynamicDataRoutes(System.Web.Routing.RouteCollection routes) { DefaultModel.FieldTemplateFactory = new SecureFieldTemplateFactory(); ContextConfiguration config = new ContextConfiguration() { ScaffoldAllTables = true }; DefaultModel.RegisterContext(typeof(Weavver.Data.WeavverEntityContainer), config); DefaultModel.RegisterContext(typeof(Weavver.Workflows.WorkflowContainer), config); // separate page mode routes.Add(new DynamicDataRoute("{table}/{action}.aspx") { Constraints = new System.Web.Routing.RouteValueDictionary(new { action = "BlogRoll|PressRoll|StoreItem|Showcase|Page|XML|List|Details|Insert|ListDetails|CSV|Edit" }), RouteHandler = new SecureDynamicDataRouteHandler(), Model = DefaultModel }); //routes.Add(new DynamicDataRoute("{table}/{action}.aspx") //{ // Constraints = new System.Web.Routing.RouteValueDictionary(new { action = }), // RouteHandler = new DynamicDataRouteHandler(), // Model = DefaultModel //}); // combined page mode routes.Add(new DynamicDataRoute("{table}/KnowledgeBase.aspx") { Action = PageAction.List, RouteHandler = new DynamicDataRouteHandler(), ViewName = "KnowledgeBase", Model = DefaultModel }); //routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") //{ // Action = PageAction.List, // RouteHandler = new SecureDynamicDataRouteHandler(), // ViewName = "ListDetails", // Model = DefaultModel //}); }