【问题标题】:The 'SubCatNewsID' property on 'SubCatNews' could not be set to a 'Boolean' value. You must set this property to a non-null value of type 'Int32无法将“SubCatNews”上的“SubCatNewsID”属性设置为“布尔”值。您必须将此属性设置为“Int32”类型的非空值
【发布时间】:2012-05-05 07:27:31
【问题描述】:

我有时会收到此错误,但我没有采取任何措施

这是随机出现的

我使用这个框架: CodeFirst 类型中的实体,Mvc3

有时我会在不同的数据类型或其他模型中遇到此错误:

Cat”上的“CatID”属性无法设置为“布尔”值。您必须将此属性设置为“Int32”类型的非空值

“Cat”上的“CatID”属性无法设置为“String”值。您必须将此属性设置为“Int32”类型的非空值

我的网站主题是新闻发布,我的客户操作员在全天休息时使用网站并插入/编辑数据

编辑: 我看到这个错误不是针对页面的,当我有这个错误时,我的网站中没有页面没有加载并且所有页面都有这个消息

我的模特:

public class SubCatNews
{
    [Key]
    public int SubCatNewsID { get; set; }
   // [EdmScalarPropertyAttribute(IsNullable = true)]
   // public int? SubCatID { get; set; }
    [Required(ErrorMessage = "some error")]
    public string Title { get; set; }
    [Required(ErrorMessage = "some error")]
    [AllowHtml]
    [DataType(DataType.Html)]
    public string Summary { get; set; }
    [Required(ErrorMessage = "some error")]
    [AllowHtml]
    [DataType(DataType.Html)]
    public string Details { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public bool? ImpStatus { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]
    public DateTime? Created { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public bool? Visible { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public string pic { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public int? UsersID { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public int? StatusID { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public int? NewsTypeID { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public int? ZonesID { get; set; }
    [EdmScalarPropertyAttribute(IsNullable = true)]
    public int? lanID { get; set; }
    //public int RatingSubCatNewsID { get; set; }



    public virtual Users Users { get; set; }
   // public virtual SubCat SubCat { get; set; }
    public virtual NewsStatus Status { get; set; }
    public virtual NewsType NewsType { get; set; }
    public virtual ICollection<SubCatNewsComment> SubCatNewsComments { get; set; }
    public virtual ICollection<NewsInSubCat> NewsInSubCatss { get; set; }
    public virtual ICollection<SubNewsInTag> SubNewsInTags { get; set; }
    //public virtual RatingSubCatNews RatingSubCatNews { get; set; }
}

但我想知道,当我在 web.config 中进行任何更改时,网站就会启动!

这是为了在实体中缓存​​数据和值

我的上下文创建者:

public abstract class BaseController<TEntityType, TIdType> : ContextGridController<HNewsPortalContext, TEntityType, TIdType>
    where TEntityType : class
{
    protected override HNewsPortalContext CreateContext()
    {
        return new HNewsPortalContext(); 
    }
}

在此之前,我的 Context Creator,像这样返回 Context:

HNewsPortalContext.Singleton;

我猜这是因为静态上下文和实体缓存导致这个错误,但是新上下文,不要修复我的错误

现在当我的网站出现此错误时,我在 web.config 中进行一些更改(在关闭或 RemoteOnly 之间切换自定义错误模式值)并保存它,然后网站就启动了

请帮帮我 坦克

我的完整错误信息: full message image full message image

【问题讨论】:

    标签: asp.net-mvc-3 entity-framework model


    【解决方案1】:

    附加调试器、中断异常并检查堆栈跟踪以查看哪些代码正在设置您的属性。

    【讨论】:

    • 我在第一篇文章中添加了完整的错误消息图像,tanx,够了吗?请为我解释一下
    • 您需要调试您的代码。如果您不知道如何调试代码,请向同事寻求帮助。
    【解决方案2】:

    我检查了一下,发现这是因为我的应用程序池溢出了 我的站点在共享服务器上,会话过期时间很长

    完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多