EF中出现以下错误的问题无法将值NULL插入“Discriminator”列中 [英] Problem with the following error in EF Cannot insert the value NULL into column 'Discriminator

查看:174
本文介绍了EF中出现以下错误的问题无法将值NULL插入“Discriminator”列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在库中有以下poco类。

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; }
   }





我还有几个其他poco类引用这个类,如下所示





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; }
    }





我也使用-EnableAutomaticMigrations标志进行数据库迁移。



我的问题是当我在我的DataContext中调用方法SaveChanges()时,我收到以下错误消息。



无法插入值NULL进入判别者栏目



我知道这意味着EF认为某些课程来自产品,但事实并非如此。



你能帮忙解决这个问题吗?



谢谢你,



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,

推荐答案

您必须查看数据库并查看列Discriminator如何定义。您会发现这是不可为空的列...

您有多个选项,包括make column nullable或者为它定义默认值...
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...


我发现了问题所在。



我正在调用库我的单元测试库并没有' t具有在该app.config中定义的正确连接字符串,这导致了这个问题。
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.


这篇关于EF中出现以下错误的问题无法将值NULL插入“Discriminator”列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆