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 8539955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:29:21+00:00 2026-06-11T11:29:21+00:00

I’ve got two tables: Documents(Id, DocumentTypeId, Title, Details) DocumentTypes (Id, Name, Description). DocumentTypeId is

  • 0

I’ve got two tables:

  • Documents(Id, DocumentTypeId, Title, Details)
  • DocumentTypes (Id, Name, Description).

DocumentTypeId is a foreign key that refers to DocumentTypes table. I.e. all documents can should
have a type assigned to them.

I’ve got two classes:

public class Document
{
    public string Id { get; set; }
    public string Title { get; set; }
    public DocumentType DocumentType { get; set; }
}

and

public class DocumentType
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
}

and I’ve got a configuration

internal class DocumentsConfiguration : EntityTypeConfiguration<Document>
{
    public DocumentsConfiguration()
    {
        ToTable("Documents");
        HasKey(document => document.Id);
        Property(document => document.Id).HasColumnName("Id");

        HasRequired(document => document.DocumentType);//????????

        Property(document => document.Title).HasColumnName("Title").IsRequired();
    }
}

And this is not working. I’m getting this error message:

Invalid column name 'DocumentType_Id'

If I rename the fk column to be DocumentType_Id then I’m getting this error message:

Invalid column name 'DocumentTypeId'

My question is how do I set such one-to-many relation? I.e. I’d like to have many documents with different document types.

  • 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-11T11:29:23+00:00Added an answer on June 11, 2026 at 11:29 am

    First make this change. Navigation properties have to be virtual:

    public class Document
    {
        public string Id { get; set; }
        public string Title { get; set; }
        public virtual DocumentType DocumentType { get; set; }
    }
    

    Then change your configuration to this:

    internal class DocumentsConfiguration : EntityTypeConfiguration<Document>
    {
        public DocumentsConfiguration()
        {
            HasRequired(document => document.DocumentType)
                .WithMany()
                .Map(e => e.MapKey("DocumentTypeId"));
            Property(document => document.Title).HasColumnName("Title").IsRequired();
            ToTable("Documents");
        }
    }
    

    You don’t need the HasKey or Property calls for the Id field because they are already assumed by convention. Your table must have a column DocumentId in this configuration.

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

Sidebar

Related Questions

I've got two tables that have related items through a connection-table. The connection table
I've got two tables: TABLE A (columns: FirstValue, SecondValue, SeatNumber) currently empty TABLE B(1
I've got two tables with similar structure: - First table: id and col1,col2,col3 -
I have got two tables: Event +----------+---------+--------------+ | event_id | name | date |
Say I've got two tables: Parent id | name Child id | parentId |
I have got two tables in SQL Server 2005: USER Table: information about user
I have got two tables: threads: id, title posts: id, thread_id, body I want
I've got two tables: Table 1 = idhash - username - usermail Table 2
The scenario I've got two tables with identical structure. TABLE [INFORMATION], [SYNC_INFORMATION] [ITEM] [nvarchar](255)
I've essentially got two tables: Page(PK=url) and PageProperty(PK=url+name). Here is how I have my

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.