title: Entities and Dynamic Data Site: references between tables
body: <p>I have two tables:</p>
  
  <pre><code>CREATE TABLE [dbo].[Context] (
    [Identity] int IDENTITY (1, 1) NOT NULL, 
    [Naam] nvarchar (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, 
    [Code] nvarchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, 
    [Omschrijving] ntext COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ; 
  ALTER TABLE [dbo].[Context] 
    ADD CONSTRAINT [PK_Context] 
        PRIMARY KEY ([Identity]) ; 
  ALTER TABLE [dbo].[Context] 
    ADD CONSTRAINT [IX_Context_Naam] 
        UNIQUE ([Naam]) ; 
  ALTER TABLE [dbo].[Context] 
    ADD CONSTRAINT [IX_Context_Code] 
        UNIQUE ([Code]) ; 
  CREATE TABLE [dbo].[Component] (
    [Identity] int IDENTITY (1, 1) NOT NULL, 
    [ContextLink] int NOT NULL, 
    [Naam] nvarchar (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, 
    [Code] nvarchar (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, 
    [Omschrijving] ntext COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ; 
  ALTER TABLE [dbo].[Component] 
    ADD CONSTRAINT [FK_ComponentContext] 
        FOREIGN KEY ([ContextLink]) 
          REFERENCES [dbo].[Context] ([Identity]) ; 
  </code></pre>
  
  <p>(Above script should create both.)
  Basically, I have a Component table that refers to the Context table.</p>
  
  <p>I created a Dynamic Data Site using both tables and .NET will take care of the references for me. It's a good way to quickly provide some basic website so we can continue to work on the business logic first.</p>
  
  <p>However, when I look at the Component table in the DDS, I notice that the reference shows the <em>code</em> field of the context, not the <em>Name</em> field. So, how do I force the DDS to use the Name field instead when displaying the reference link to the context table?</p>
  
  <p>(Preferably by using something simple, since I'm dealing with over 60 tables that are similar to this one. Most of them simple lookup tables to make filtering easier.)</p>
  
  <p>Since we're not going to work on the GUI side of this web application for a few months, it's no option to alter something in the DDS source itself. If it can be fixed in the database or Entity model, then please let me know!</p>
  
  <hr>
  
  <p>The datamodel I use for this project is simple: every table has a primary key "Identity" which is an autoIncrement field. The Code and Naam (name) fields are to describe specific data and is used in other applications to fill up comboboxes and filters. These applications don't communicate directly with the database but they use an export XML based on the database. In this export XML, the links to "Identity" get replaced by links to "Code". This allows the user to change the code to whatever they like without the need to walk through the whole database to adjust the references.
  The database has only one purpose: to make it easier for several users to maintain the XML data that another application uses. We have about 5 persons who make modifications to this data about 24/7 and an export XML is generated about once per week, which is then sent to our customers. (Who mostly use this data in an offline application, on laptops with limited internet connectivity.)</p>