0

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

这个随机出现

我使用这个框架: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 之间切换自定义错误模式值)并保存它,然后站点启动

请帮帮我

我的完整错误消息: 完整消息图像 完整消息图像

4

2 回答 2

1

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

于 2012-05-05T07:31:48.233 回答
-1

我检查并看到这是因为我的应用程序池溢出我的站点位于共享服务器上并且会话过期时间很长

结束

于 2012-05-09T07:01:48.987 回答