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

  • Home
  • SEARCH
  • 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 9225551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:36:18+00:00 2026-06-18T04:36:18+00:00

I’m a newbie at linq, Ajax and c#. I am not new to SQL

  • 0

I’m a newbie at linq, Ajax and c#. I am not new to SQL Server, or VB. I am getting the error:

'ReportTypeID' is not a foreign key column and cannot be used here.

Yes I looked at http://forums.asp.net/t/1254559.aspx and found one of my errors.

No, I am not using views so “…is not a foreign key column and cannot be used here?” was of little use.

As far as I can tell, it is correctly configured to handle the foreign key.

The two tables are configured as follows:

CREATE TABLE [dbo].[Report](
    [Id] [INT] IDENTITY(1,1) NOT NULL,
    [ReportTypeID] [INT] NOT NULL,
 CONSTRAINT [PK_Report] PRIMARY KEY CLUSTERED
(
    [Id] 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].[Report] ADD CONSTRAINT [DF_Report_ReportTypeID]  DEFAULT ((1)) FOR [ReportTypeID]
GO
ALTER TABLE [dbo].[Report]  WITH CHECK ADD  CONSTRAINT [FK_Report_ReportType] FOREIGN KEY([ReportTypeID])
REFERENCES [dbo].[ReportType] ([TypeValue])
GO
ALTER TABLE [dbo].[Report] CHECK CONSTRAINT [FK_Report_ReportType]
GO
CREATE TABLE [dbo].[ReportType](
    [TypeValue] [INT] NOT NULL,
    [TypeDescr] [VARCHAR](50) NOT NULL,
 CONSTRAINT [PK_ReportType] PRIMARY KEY CLUSTERED
(
    [TypeValue] 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

The SQL join is as follows:

SELECT * FROM Report r INNER JOIN ReportType rt ON r.ReportTypeID = rt.TypeValue

Finally, the C# dbml definitions on the appropriate columns (much attenuated) are as follows:

<Table Name="dbo.Report" Member="Reports">
  <Type Name="Report">
    <Column Name="ReportTypeID" Type="System.Int32" DbType="INT NOT NULL" CanBeNull="false" />
    <Association Name="ReportType_Report" Member="ReportType" ThisKey="ReportTypeID" OtherKey="TypeValue" Type="ReportType" IsForeignKey="true" />
  </Type>
</Table>
<Table Name="dbo.ReportType" Member="ReportTypes">
  <Type Name="ReportType">
    <Column Name="TypeValue" Type="System.Int32" DbType="INT NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
    <Association Name="ReportType_Report" Member="Reports" ThisKey="TypeValue" OtherKey="ReportTypeID" Type="Report" />
  </Type>
</Table>

The SQL works correctly and there are no dis-joins in the data, the data is correct when I step through the program. The value of the ReportTypeID=1 which is valid.
The TypeValue in the ReportType table is not auto generated, it is unique and a primary key.
I suspect this has something to do with the dbml definitions. I am still definitely missing something.
edit: Add the visual relation. The setting is based on the other relation in the image which works.Visual Relation Of Tables

The error is reported in the Ajax field template code “ForeignKeyRequired_Edit.ascx.cs”

protected override void OnDataBinding(EventArgs e)
{
  base.OnDataBinding(e);

  if (Mode == DataBoundControlMode.Edit)
  {
    string foreignkey = ForeignKeyColumn.GetForeignKeyString(Row); // Error On This Line
    ListItem item = DropDownList1.Items.FindByValue(foreignkey);
    if (item != null)
    {
      DropDownList1.SelectedValue = foreignkey;
    }
  }
}

Edit I believe I found the problem, I need some documentation to find the answer.
There is a switch statement in the code that requires editing. I’m getting to my template, but not to my field.

case "Source": // This Works
  items = StaticCache.Sources.AsQueryable().Where(att.WhereClause).Select(r => new ListItem { Text = r.Name, Value = r.Id.ToString() }).ToArray();
  break;
// Problem Code - This One Doesn't - Not Sure Which Of These To Use
case "ReportTypeTable": // Based On The Table Definition -- Internal Doc Points To This One
  items = StaticCache.ReportTypes.AsQueryable().Where(att.WhereClause).Select(r => new ListItem { Text = r.TypeDescr, Value = r.TypeValue.ToString() }).ToArray();
  break;

Edit
The “ReportType” table is considered to be an “invalid object” by SQL Server. Could this be the problem?

edit
I’m now looking into active directory as a possible problem. Edit Not an active directory problem and the “invalid object” error was an intellesense problem (fixed).

Edit: I have part of the answer. The documentation is not clear. The answer lies in the dbml definition of the table. Fortunately I renamed each level of that table so that references to each of the levels of “ID” in the definition had unique, but related, names. The partial answer is to use the dbml table name. I no longer get this error. I just don’t have any data in the dropdown list. See: http://www.seekwaytech.com/2011/02/27/asp-net-4-0-dynamic-data-foreign-keys-show-up-in-a-text-box/ and http://forums.asp.net/t/1254559.aspx
in that order. (The first explains the answer to the second)

Edit Finally, getting rid of all of the garbage tests and going back to the dynamic object did the job.

<asp:DynamicControl runat="server" DataField="ReportTypeTable" DataValueField="TypeValue" DataTextField="TypeDescr" Mode="Edit" UIHint="ForeignKeyRequired" CssClass="general" /> 
  • 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-06-18T04:36:19+00:00Added an answer on June 18, 2026 at 4:36 am

    The documentation is not clear. The answer lies in the DBML definition of the table. Fortunately I renamed each level of that table so that references to each of the levels of “ID” in the definition had unique, but related, names. The partial answer is to use the DBML table name. I no longer get this error. I just don’t have any data in the dropdown list. See: http://www.seekwaytech.com/2011/02/27/asp-net-4-0-dynamic-data-foreign-keys-show-up-in-a-text-box/ and http://forums.asp.net/t/1254559.aspx
    in that order. (The first explains the answer to the second)

    Finally, I went back to the original definition of the object and added the “DataValueField” and the “DataTextField” to the control. It now works as needed.

    <asp:DynamicControl runat="server" DataField="ReportTypeTable" DataValueField="TypeValue" DataTextField="TypeDescr" Mode="Edit" UIHint="ForeignKeyRequired" CssClass="general" /> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

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.