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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:27:02+00:00 2026-05-30T10:27:02+00:00

I have two tables in my database which have a one-to-one relationship. I want

  • 0

I have two tables in my database which have a one-to-one relationship. I want to access them with EF using the code first approach. I have written the POCO classes like this:

public class User
{
    public int Id { get; set; }
    public string Login { get; set; }
    public string Password { get; set; }
    public string Email { get; set; }

    public virtual Profile Profile { get; set; }
}

public class Profile
{
    public int UserId { get; set; }
    public string FullName { get; set; }
    public DateTime? Birthday { get; set; }
    public bool? Male { get; set; }
}

And also I described the relationships between that classes in the OnModelCreating as explained here. So that’s how looks:

modelBuilder.Entity<Profile>().HasKey(x => x.UserId);
modelBuilder.Entity<User>().
    HasOptional(u => u.Profile).
    WithRequired();

But when I run the application I’m getting this exception when trying to access the User tables:

Invalid column name “User_Id”

Although when I let EF create a new database on its own with these two tables, it creates a database that has the same structure as mine and it works.

I was using EF 4.3 (I tried 4.2 too) and MS SQL 2008. What am I doing wrong? I can’t believe that it’s a bug of Entity Framework.

  • 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-30T10:27:03+00:00Added an answer on May 30, 2026 at 10:27 am

    Thank you, guys, for your help. I realized that code first is not the way I should go and I have chosen the database first approach. With the POCO templates for the Entity Framework.

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

Sidebar

Related Questions

I have two database tables with a one-to-many relationship. Is it possible to select
I have a database that which contains two tables, links and tour. Tour is
I have two tables in MySql database, one is sales_order and the other is
I have database which has two tables post: id post_name post_desc files: file_id file_name
I have two tables with hierarchyid fields, one of which is a staging table
I have two tables Question and Option having one to many relationship. after fetching
I have two tables in my application. The first one, Sections, stores content for
I have a database model with two tables: Session and ScriptExecution which are associated
I have a table and two databases which have the same table, but one
I have two database tables, 1st is the TABLE_GLOBAL_PRODUCTS where all products information are

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.