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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:24:42+00:00 2026-05-24T06:24:42+00:00

I have these classes: public class Product { [Key] public virtual int ProductId {

  • 0

I have these classes:

public class Product
{
    [Key]
    public virtual int ProductId { get; set; }
    public virtual string ProductName { get; set; }
    public virtual string Category { get; set; }

    public virtual IList<ProductPricing> ProductPriceList { get; set; }


    [Timestamp]
    public virtual byte[] Version { get; set; }
}

public class ProductPricing
{        

    // no ProductId here
    public virtual Product Product { get; set; }

    [Key]
    public virtual int ProductPricingId { get; set; }

    public virtual DateTime EffectiveDate { get; set; }
    public virtual decimal Price { get; set; }


}

This is my modelBuilder:

modelBuilder.Entity<Product>().
    HasMany(x => x.ProductPriceList)
   .WithRequired()
   .HasForeignKey(x => x.Product);

This is the error:

The foreign key component ‘Product’ is not a declared property on
type ‘ProductPricing’. Verify that it has not been explicitly excluded
from the model and that it is a valid primitive property.

UPDATE

I’ve tried the following, corresponding errors below the code

modelBuilder.Entity<Product>()
    .HasMany(x => x.ProductPriceList)
    .WithRequired();

{“Invalid column name ‘Product_ProductId1’.\r\nInvalid column name
‘Product_ProductId’.\r\nInvalid column name ‘Product_ProductId1’.”}

modelBuilder.Entity<Product>()
    .HasMany(x => x.ProductPriceList)
    .WithRequired()
    .Map(x => x.MapKey("ProductId"));

{“Invalid column name ‘Product_ProductId’.”}

modelBuilder.Entity<Product>()
    .HasMany(x => x.ProductPriceList)
    .WithRequired(x => x.Product);

{“Invalid column name ‘Product_ProductId’.\r\nInvalid column name
‘Product_ProductId’.”}

modelBuilder.Entity<Product>()
    .HasMany(x => x.ProductPriceList)
    .WithRequired(x => x.Product)
    .Map(x => x.MapKey("ProductId"));

{“Multiplicity constraint violated. The role
‘Product_ProductPriceList_Source’ of the relationship
‘TestEfCrud.Mappers.Product_ProductPriceList’ has multiplicity 1 or
0..1.”}

If it could help, here’s the DDL:

create table Product
(
ProductId int not null identity(1,1) primary key,
ProductName varchar(100) not null,
Category varchar(100) not null,
Version rowversion not null
);

create table ProductPricing
(
ProductId int not null references Product(ProductId),
ProductPricingId int identity(1,1) not null primary key,
EffectiveDate datetime not null,
Price decimal(18,6) not null
);

UPDATE 2

I’ve tried this answer, which looks a bit similar to my case, mapping originated from child entity
How to map parent column in EF 4.1 code first

However, using this:

modelBuilder.Entity<ProductPricing>()
    .HasOptional(x => x.Product)
    .WithMany()
    .Map(x => x.MapKey("ForeignKeyColumn"));

and this:

modelBuilder.Entity<ProductPricing>()
    .HasRequired(x => x.Product)
    .WithMany()
    .HasForeignKey(x => x.Product);

Both resulted to this error:

{“Invalid column name ‘Product_ProductId1’.\r\nInvalid column name
‘Product_ProductId1’.\r\nInvalid column name ‘Product_ProductId1’.”}

  • 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-24T06:24:43+00:00Added an answer on May 24, 2026 at 6:24 am

    I don’t understand why do you use fluent mapping? Your model should be mapped by default conventions. If you want to map it with fluent mapping use:

    modelBuilder.Entity<Product>()
                .HasMany(x => x.ProductPriceList) // Product has many ProductPricings
                .WithRequired(y => y.Product)     // ProductPricing has required Product
                .Map(m => m.MapKey("ProductId")); // Map FK in database to ProductId column
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these classes: public class MovieExt { public string Title { get; set;
I have these classes: public class RegionResult { public string Region { get; set;
Let's say we have these two classes: public class Base { public static int
Concerning data binding I have these classes: public class Foo : List<Bar> { public
I have these two classes public class Person { } public class Company {
I have these classes in C# (.NET Framework 3.5) described below: public class Base
I have these classes. class Author{ Person person } class Person{ String lastName String
public class Client { public Int32 ClientID { get; set; } public virtual ICollection<Inquiry>
I have the following classes: public class CartItem { public long Id { get;
let's have these classes: public class MyObject { //constructor and other stuff public bool

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.