Dynamic Data FAQ

Please post corrections/new submissions to the Dynamic Data Forum. Put FAQ Submission/Correction in your title.

See Tips on getting your ASP.NET Dynamic Data questions answered quickly

Post LINQ To SQL Questions here
Post Entity Framework Questions here

Links that will answer questions:

From the Dynamic Data architect David Ebbo

From https://blogs.msdn.com/rickAndy  (Most samples include VB)

From ASP.Net Developer David Fowler

Q: How do I get started with Dynamic Data?
A: If you like videos, see ASP.NET Dynamic Data videos
     MSDN on Dynamic Data
     Walkthrough: Creating a New ASP.NET Dynamic Data Web Site Using Scaffolding
     Dynamic Data Forum

Q: What's new with Dynamic Data for .Net 4 Beta? <-- New
A: See this link.

Q: The data annotation to my partial class is not working?
A: The most common problem is no namespace or incorrect namespace around your partial class. A partial class that is not part of the data model (or part of another class) is known as a naked partial class. The easiest way to test if you have a naked partial class is to add a non-existing field to the partial class. In the following snippet,  bogus is not in the CustomerAddress table.

   public partial class CustomerAddress {
       public class CustomerAddressMetaData {

           public object ModifiedDate;

           public object bogus;

When you run the Dynamic Data project, you will get the following exception in DefaultModel.RegisterContext (in global.asax):

The associated metadata type for type 'DynamicDataProject.CustomerAddress' contains the following unknown properties or fields: bogus. Please make sure that the names of these members match the names of the properties on the main type.

Q: How do I generate GUIDs on inserts?
A: You don't, you shouldn't. Let the DB generate them or you will have performance problems. You can modify the data model XML and explicitly state they are DB generated. With the EDM, use StoreGeneratedPattern="Computed"  while Linq to SQL uses IsDbGenerated="true"

Q: How to set Displayformat for a password field?
A: See Steve's excellent Password FieldTemplates for Dynamic Data

Q: How do I check for duplicates before I insert? (Or get values from the DB for any reason before I insert)
A: see this post.

Q: How do I mark a columns as read-only?
A: see this post or Making a Field Read-Only via the ReadOnlyAttribute – Dynamic Data - Note the next version of Dynamic Data And The ASP.NET Dynamic Data 4.0 Preview 3 support the [ReadOnly(true)] attribute.

Q: Can Dynamic Data use a data model generated by a 3rd party O/RM tool?
A:The current Dynamic Data needs the following items to work with a technology:
-    Technology must support Linq
-    DataSource control must exist for the technology
-    Dynamic Data ModelProvider must exist for the technology

An example of one today is LLBLGen: https://www.llblgen.com/defaultgeneric.aspx

nHibernate currently does not meet the Linq requirements.

Q: What DB's are supported?
A: See ADO.NET Entity Framework Providers

Q: How do I hide columns from the Edit and other page templates?
A: Suppose you want to display the Salary field, but you don't want to show it in the Edit and Insert templates. See Stephens popular tutorial

Dynamic Data - Hiding Columns in selected PageTemplates

Q: How do I disallow navigation links on Foreign Key columns?
A: By default, DD displays the first string column in the Foreign Key table in stead of the FK. This is rendered as a link (NavigateUrl) to the FK table. If you're not happy with the default (column shown) use the DisplayColumn attribute on the FK table to specify which property is displayed. See also Improving the FK field display: Showing two fields in Foreign Key columns. Back to the original question. The easiest way to disable the FK property from being a NavigateUrl is to hide the FK table by annotating your entity partial class with the ScaffoldTable   attribute. Note,  ScaffoldTable   will hide your table. If you want to expose your table but disable the hyperlink - see Stephens excellent blog Allow Navigation on ForeignKey FieldTemplate – Dynamic Data

Q: How do I move the Edit Delete Details links from the left side (column 0) to the right side of the table.
A: Create your own IAutoFieldGenerator.GenerateFields and add the command field at the end. (thx David Fowler). See this post.

Q: How do I implement role based security? (tables/columns visibility dependent on users role).
A: See this post, and custom IAutoFieldGenerator

Q: How do map stored procedures (sprocs) to Inserts and get back the auto generated PK using L2S?
A: See LINQ to SQL (Part 7 - Updating our Database using Stored Procedures) , Stored Procedures (LINQ to SQL) and How to override default insert method of Details View in Dynamic Data .