Databases Reference
In-Depth Information
Data Annotations
Entity classes used by Entity Framework and LINQ to SQL can be decorated with a number
of different .NET attributes. Some of these attributes have special meaning for Dynamic
Data and are represented as distinct properties in the MetaTable class:
public virtual bool Scaffold { get; }
The Scaffold property of the MetaTable class determines whether the table will be visible
(or scaffolded) in the pages generated by Dynamic Data. This includes not only the default
main page that simply displays a list of all tables, but also the pages that might include
hyperlinks to particular tables. For example, if the Suppliers table is not scaffolded, you
will not be able to navigate to it from the Product details page:
using System.ComponentModel.DataAnnotations;
[ScaffoldTable(false)]
partial class Supplier { }
By default, the Scaffold property value is determined by the value of the ScaffoldAllTables
property of the ContextConfiuration object used to register the context. However, it can
be also modified by applying the ScaffoldTableAttribute to a specific entity class as just
shown:
public virtual bool IsReadOnly { get; }
The IsReadOnly property of the MetaTable class determines whether users are allowed to
modify it. The page templates created by Dynamic Data projects in Visual Studio use this
property to hide links that would normally allow users to insert, modify, and delete the
table rows:
using System.ComponentModel;
[ReadOnly(true)]
partial class Supplier { }
By default, the IsReadOnly property returns true for tables that don't have a primary key,
which could be the case if the MetaTable represents an entity class that was created for a
database view, for which the Entity Framework and LINQ to SQL cannot automatically
determine the primary key columns. You can also apply the ReadOnlyAttribute to the
entity class as just shown to explicitly specify this value based on your needs:
public virtual string DisplayName { get; }
The DisplayName property of the MetaTable class determines the text Dynamic Data page
templates display when a human-readable name of the table is required on a dynamically
generated web page. By default, the DisplayName property returns the same value as the
Name property. If, however, the table name is not user-friendly, such as the Order_Details
 
Search WWH ::




Custom Search