首页 > 解决方案 > 值不能为空。参数名称:entitySet,稍微更改模型时出现此错误

问题描述

这是我的模型,一切正常:

public class events1
{
    public int Id { get; set; }
    public string title { get; set; }
    public string report { get; set; }
    public string image1 { get; set; }
    public string image2 { get; set; }       
}

我只是出于特定目的在模型中添加了这一行,现在当我添加新迁移时,它说:

值不能为空。参数名称:实体集

我的新模型是这样的:

public class events1
{
    public int Id { get; set; }
    public string title { get; set; }
    public string report { get; set; }
    public string image1 { get; set; }
    public string image2 { get; set; }

    //the new added line//

    public HttpPostedFileBase ImageFile { get; set; }
}

标签: c#asp.net-mvc

解决方案


如果您没有将属性映射到数据库中,您可以将其标记为未映射。

[NotMapped]
public HttpPostedFileBase ImageFile { get; set; }

您可以使用以下 using 语句来获取属性

using System.ComponentModel.DataAnnotations.Schema

推荐阅读