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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:57:57+00:00 2026-05-26T15:57:57+00:00

I followed Using EF Code First with an Existing Database tutorial step by step

  • 0

I followed Using EF “Code First” with an Existing Database tutorial step by step but getting the following Error :

Invalid column name Category_CategoryID

Following is the code Excerpt :

public class Product
{
    public int ProductID { get; set; }
    public string ProductName { get; set; }
    public decimal? UnitPrice { get; set; }
    public bool Discontinued { get; set; }

    public virtual Category Category { get; set; } 
}

public class Category
{
    public int CategoryID { get; set; }
    public string CategoryName { get; set; }
    public string Description { get; set; }
    public byte[] Picture { get; set; }

    public virtual ICollection<Product> Products { get; set; }
}

Why does this happen.

EDIT – I am able to make this work by including public int CategoryID in Product Class but dont know the details.

  • 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-26T15:57:58+00:00Added an answer on May 26, 2026 at 3:57 pm

    You need to let EF know that Products.Category is the inverse of Category.Products. I’m not sure why that’s not shown in ScottGu’s blog post.

    The code you need would be something like this in your DbContext subclass:

    protected override void OnModelCreating(ModelBuilder modelBuilder {)
      modelBuilder.Entity<Product>().HasOne(p => p.Category).WithMany(c => c.Products);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First time using Asp.net-mvc and originally followed the NerdDinner tutorial. My form submit button
So followed all the basic tutorials. Am using Zend 1.8 but i keep getting
I followed this tutorial: https://github.com/EllisLab/CodeIgniter/wiki/PDF-generation-using-dompdf However, I can't seem to set the path right.
I am using Zend_Framework's Zend_Controller_Action to build a facebook application. I followed the step
I followed the Flex and Bison tutorial to learn flex & bison , but
I've followed the following tutorial, in the simulator it works great, however on my
I'm trying to map a fairly standard category model using EF Code First public
I am using Entity Framework 4.1 code first and ASP.NET MVC 3 and I
First off, I'm using Tomcat 5.5 and my .jsp's live in /webapps/foo/bar/*.jsp. I followed
This is my first attempt at updating a database using LINQtoSQL. At least, it's

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.