Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

I have the following poco class in library.
C#
public class Product
   {
       [Key]
       public long ID { get; set; }
       public string Name { get; set; }
       public int? StockQuantity { get; set; }
       [Column(TypeName="nvarchar")]
       [MaxLength(50)]
       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

C#
public class Link
    {
        [Key]
        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,
Posted

You have to look into the database and see how column Discriminator defined. You will find that this is non-nullable column...
You have several options, including make column nullable or define default value for it...
 
Share this answer
 
I have found what the problem is.

I was calling the library from my unit test library and it didn't have the correct connection string defined in that app.config which caused this problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900