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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:51:12+00:00 2026-06-03T23:51:12+00:00

Models: public class Status { public int Id { get; set; } } public

  • 0

Models:

public class Status
{
    public int Id { get; set; }
}

public class Podcast
{
    public int Id { get; set; }

    public virtual Status Status { get; set; }
}

The Podcast table has the StatusId column, and this column is a foreign key. In this case I’ve got the following error message: Invalid column name 'Status_Id'. Why? – Many times I faced that articles with such examples. This is the first question.
Ok, no problem – i’ve added an underscore character to these columns: Sttaus_Id and so on.
Now it seems that everything works fine, but when I modify my model by the following way:

public class Podcast
{
    public int Id { get; set; }

    public int Status_Id { get; set; }

    public virtual Status Status { get; set; }
}

Now I get the following error: Invalid column name 'Status_Id1'.
Why? I can’t use the DropDownListFor helper without these xx_id properies.

  • 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-03T23:51:14+00:00Added an answer on June 3, 2026 at 11:51 pm

    I believe the issue here is that you have created your DB first and created a column named StatusId for your FK reference but you haven’t told EF that you are using a non-default column name for your FK.

    the following will give you the structure you are after (ps i agree with your naming convention i personally dislike the _ in fk ids)

        public class MyContext : DbContext
        {
            public DbSet<Podcast> Podcasts { get; set; }
            public DbSet<Status> Status { get; set; }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Entity<Podcast>().HasOptional(p => p.Status)
                    .WithMany().HasForeignKey(p => p.StatusId);
                base.OnModelCreating(modelBuilder);
            }
        }
    
        public class Status
        {
            public int Id { get; set; }
        }
    
        public class Podcast
        {
            public int Id { get; set; }
    
            public int? StatusId { get; set; }
            public virtual Status Status { get; set; }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Models : public class EvaluationCriteriaItem { public int ID {
i have these two models public class Group { [Key] public int GroupID {
I have these view models. public class MasterFrmVm { public Guid Id { get;
I have model public class QuestionViewModel { public string Text { get; set; }
I have an Abstract class: [Serializable] public abstract class BaseModel { public virtual int
I have the following types and classes: namespace MVC.Models public class Page { public
I have Car and Rental models conntected OneToMany relation: @Entity public class Rental {
Suppose I have the view models below. public class CustomerListViewModel { public IEnumerable<CustomerViewModel> Customers
My model: public class Father { Set<Son> sons = new HashSet<Son>(); String name =
I have a domain model: public class Project { [Key] public int ProjectID {

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.