Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6186751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:56:31+00:00 2026-05-24T01:56:31+00:00

I have a Dynamic Data 4 site using LinqToSql (.dbml) for 2 tables with

  • 0

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.

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:

Childtable/Detail.aspx?ChildPkField=PRIMARYTABLEGUID

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

 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));
        }
    }

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.

I am sure it i something simple but I have looked at it for too long now – any help appreciated!

Here are the current Create Table Scripts from Sql Manager:

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

and

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:56:32+00:00Added an answer on May 24, 2026 at 1:56 am

    In fact, the first method you used is perhaps the most optimal solution as the query has already been made on the server-side to determine whether the column data matches the foreign key relationship. No more querying is needed, just test FieldValue == null. Besides, the template controls are there to be edited, which is why they’re not compiled to assemblies:

    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));
        }
    }
    

    However, if you intend to preserved the value of the source field, use this method instead:

    protected string GetNavigateUrl()
    {
        //replace this
        //if (!AllowNavigation)
        //with this
        if (!AllowNavigation || FieldValue == null)
        {
            return null;
        }
        if (String.IsNullOrEmpty(NavigateUrl))
        {
            return ForeignKeyPath;
        }
        else
        {
            return BuildForeignKeyPath(NavigateUrl);
        }
    }
    

    Under certain conditions (including the default css styles), it will generate a hyperlink-looking field that cannot be clicked. You can use jQuery to filter and remove those false hyperlinks by setting their outerHTML as their innerHTML (client-side scripting). Of course, there are more elegant methods like adding a <asp:label> to the ForeignKey.ascx and switching to that control when needed.

    Note: this method works when using ADO.NET Entity Data Model. I didn’t try it on LinqToSqlClasses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ASP.NET Dynamic Data for a project and I have a table
I have created a Dynamic Data site against an Entity Framework Model I have
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
I have a Dynamic Data website built in Visual Studio 2008 using .NET 3.5
I am using jQuery datatables in a dynamic PHP site. I have a page
I'm using Entity Framework 4 and a Dynamic Data site to expose a bare-bones
I have a product admin web site that has been generated using ASP.NET Dynamic
I have a Dynamic Data Entities Web Application that uses a database with GUIDs
Dynamic Data question: I have 2 fields of type Nullable<DateTime> on my model When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.