Click here to Skip to main content
14,021,911 members
Rate this:
 
Please Sign up or sign in to vote.
Hi Everyone,

I have the following poco class in library.
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

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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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...
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.190417.4 | Last Updated 30 Oct 2014
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