1

I have the following class/entity:

 public class Product : ISaleable
    {


        public void  ProcessSale()
        {
            return;
        }

        [NotMapped]
        private int id { get; set; }
        [NotMapped]
        private string productName { get; set; }
        [NotMapped]
        private decimal price { get; set; }
        [NotMapped]
        private TaxClass taxClass { get; set; }
        [NotMapped]
        private int quantity { get; set; }
        [NotMapped]
        private Member memberAssociation { get; set; }


        public TaxClass  TaxClass
        {
            get 
            {
                return this.taxClass; 
            }
            set 
            {
                this.taxClass = value; 
            }
        }
        public int  Quantity
        {
            get 
            {
                return this.quantity;
            }
            set 
            {
                this.quantity = value;
            }
        }
        public string ProductName
        {
            get
            {
                return this.productName;
            }
            set
            {
                this.productName = value;
            }
        }
        public decimal Price
        {
            get
            {
                return this.price;
            }
            set
            {
                this.price = value;
            }
        }
        public Member MemberAssociation
        {
            get
            {
                return this.memberAssociation;
            }
            set
            {
                this.memberAssociation = value;
            }
        }
        [Key]
        public int ID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }
    }

As you can see, this class inherits from ISaleable and has two elements of the type TaxClass. Now when the project is ran, and EF tries to create the table for this entity I get the following exception:

Column names in each table must be unique. Column name 'TaxClass_ID' in table 'Product' is specified more than once.

I am not sure why this is happening, any help appreciated.

1 Answer 1

2

Try renaming public TaxClass TaxClass to public TaxClass MyTaxClass.

Sign up to request clarification or add additional context in comments.

3 Comments

This worked! I had to rename the Public MemberAssocation too. Thanks!
No problem! I should point out that the reason you are getting the error in the first place is that the relationship has (probably) not been set up yet. Hence EF is unsure of how your TaxClass relates to your Product. Have a look at the article here for some more info: elegantcode.com/2009/12/15/…
I changed the column name with Property(f => f.Id).HasColumnName("MyNewID"); Not sure if this will work for you. This setting is called Fluent API btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.