Click here to Skip to main content
14,177,305 members

Problem with the following error in EF Cannot insert the value NULL into column 'Discriminator

cdpace asked:

Open original thread
Hi Everyone,

I have the following poco class in library.
public class Product
       public long ID { get; set; }
       public string Name { get; set; }
       public int? StockQuantity { get; set; }
       public string Identifier { get; set; }
       public DateTime? ReleaseDate { get; set; }
       public decimal? DefaultPrice { get; set; }
       public virtual ICollection<Language> ProductLanguages { get; set; }
       public virtual ICollection<Region> ProductRegions { get; set; }
       public virtual ICollection<Price> ProductPrices { get; set; }
       public virtual ICollection<Link> ProductLinks { get; set; }
       public virtual ICollection<Order> Orders { get; set; }

and I have serveral other poco classes referencing this class like the below

public class Link
        public Int32 ID { get; set; }
        public string Rel { get; set; }
        public string Href { get; set; }

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

I am also using database migrations with the -EnableAutomaticMigrations flag.

My problem is when I call the method SaveChanges() in my DataContext I get the following error message.

"Cannot insert the value NULL into column 'Discriminator'

I know that this means that EF thinks that there is some class that is derives from product but this isn't true.

Can you please help with this problem?

Thank you,
Tags: C# (C#4.0), entity-framework


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190526.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100