Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net Dynamic Data 4 One-to-One ForeignKey.ascx Returning Primary Key
    primarykey
    data
    text
    <p>I have a Dynamic Data 4 site using LinqToSql (.dbml) for 2 tables with a one-to-one relationship. One table (child) does not always have a row corresponding to the primary table.</p> <p>Whenever that is the case (no child table row) instead of an empty row cell the DD ForeignKey.ascx Field template is displaying a link to: </p> <pre><code>Childtable/Detail.aspx?ChildPkField=PRIMARYTABLEGUID </code></pre> <p>I can't find any combination of SQL F-key setups and/or .dbml column property settings that prevent this. The only solution so far is a Custom ForeignKey.ascx template with </p> <pre><code> protected string GetDisplayString() { object value = FieldValue; if (value == null) { //replace this //return FormatFieldValue(ForeignKeyColumn.GetForeignKeyString(Row)); //with this return ""; } else { return FormatFieldValue(ForeignKeyColumn.ParentTable.GetDisplayString(value)); } } </code></pre> <p>Obviously not an optimal solution. To simplify I have removed all Custom Metadata for both tables and all other relationships the tables were involved in. No change.</p> <p>I am sure it i something simple but I have looked at it for too long now - any help appreciated!</p> <p>Here are the current Create Table Scripts from Sql Manager:</p> <pre><code>CREATE TABLE [dbo].[UserProfile]( [UserId] [uniqueidentifier] ROWGUIDCOL NOT NULL, [ProfileUserName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_Profile] PRIMARY KEY CLUSTERED ([UserId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO ALTER TABLE [dbo].[UserProfile] ADD CONSTRAINT [DF_Profile_UserID] DEFAULT (newid()) FOR [UserId] GO </code></pre> <p>and</p> <pre><code>CREATE TABLE [dbo].[SubscribedUser]( [subUserId] [uniqueidentifier] NOT NULL, [subExpireDate] [date] NULL, CONSTRAINT [PK_SubscribedUsers] PRIMARY KEY CLUSTERED ([subUserId] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] GO ALTER TABLE [dbo].[SubscribedUser] WITH CHECK ADD CONSTRAINT [FK_SubscribedUser_UserProfile] FOREIGN KEY([subUserId]) REFERENCES [dbo].[UserProfile] ([UserId]) GO ALTER TABLE [dbo].[SubscribedUser] CHECK CONSTRAINT [FK_SubscribedUser_UserProfile] GO </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload