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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:41:11+00:00 2026-06-12T14:41:11+00:00

I have two tables StoreOrderItem StoreOrder Now StoreOrder has many StoreOrderItems and StoreOrderItem has

  • 0

I have two tables

  • StoreOrderItem
  • StoreOrder

Now StoreOrder has many StoreOrderItems and StoreOrderItem has one StoreOrder (simple 1 to many relationship)

public class StoreOrderItemMap : EntityTypeConfiguration<StoreOrderItem>
{
        public StoreOrderItemMap()
        {
            this.ToTable("StoreOrderItem");
            this.HasKey(op => op.Id);
            this.Property(op => op.StoreOrderId).HasColumnName("order_id");
            ...

            this.HasRequired(so => so.StoreOrder)
              .WithMany(soi => soi.StoreOrderItems)
              .HasForeignKey(so => so.StoreOrderId);
        }
}

public class StoreOrderMap : EntityTypeConfiguration<StoreOrder>
{
    public StoreOrderMap()
    {
        this.ToTable("StoreOrder");
        this.HasKey(op => op.Id);
        ....
    }
}

public class StoreOrderItem
{
    ....
    public virtual int StoreOrderId { get; set; }
    ....

    public virtual StoreOrder StoreOrder { get; set; }
}

public class StoreOrder
{
    .... 
    private ICollection<StoreOrderItem> _storeOrderItems;
    ....

    public virtual ICollection<StoreOrderItem> StoreOrderItems
    {
        get { return _storeOrderItems ?? (_storeOrderItems = new List<StoreOrderItem>()); }
        set { _storeOrderItems = value; }
    }

}

//The code which is used to add the configurations to the modelBuilder.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    System.Type configType = typeof(ContentMap);   //any of your configuration classes here
    var typesToRegister = Assembly.GetAssembly(configType).GetTypes()
        .Where(type => !String.IsNullOrEmpty(type.Namespace))
        .Where(type => type.BaseType != null && type.BaseType.IsGenericType && type.BaseType.GetGenericTypeDefinition() == typeof(EntityTypeConfiguration<>));
        foreach (var type in typesToRegister)
        {
            dynamic configurationInstance = Activator.CreateInstance(type);
            modelBuilder.Configurations.Add(configurationInstance);
        }
        base.OnModelCreating(modelBuilder);
}

Note I am running this code on an existing DB, how do I tell EF to not select “StoreOrder_Id” and to instead use the existing column “order_id”?

Here is the error:

Server Error in ‘/’ Application.

Invalid column name ‘StoreOrder_Id’.

Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Invalid column
name ‘StoreOrder_Id’.

  • 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-12T14:41:12+00:00Added an answer on June 12, 2026 at 2:41 pm

    Found the problem after a few days of mind bending ……

    There was another property in the StoreOrder class

    public virtual IList<StoreOrderItem> NonVoucherOrderItems
    {
        get
        {
            return this.StoreOrderItems.Where(x => !x.IsVoucher()).ToList();
        }
    }
    

    This was being evaluated too early and causing all sorts of chaos, changed to

    public virtual IEnumerable<StoreOrderItem> NonVoucherOrderItems
    {
        get
        {
            return this.StoreOrderItems.Where(x => !x.IsVoucher());
        }
    }
    

    And it worked immediately!!

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

Sidebar

Related Questions

I have two tables connected with one to many relationship. Parent Table is a
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two tables that are all the same, except one has a timestamp
I have two tables that are joined together. A has many B Normally you
I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables in my MySQL database, one is a library of all
Have two tables say ABC and XYZ and contain one column which data will
I have two tables one with an add button and one without an add
I have two tables; one with post data and in the other each row

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.