c# - 值不能为空。参数名称: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; }
}
解决方案
如果您没有将属性映射到数据库中,您可以将其标记为未映射。
[NotMapped]
public HttpPostedFileBase ImageFile { get; set; }
您可以使用以下 using 语句来获取属性
using System.ComponentModel.DataAnnotations.Schema
推荐阅读
- directus - 我可以只使用 DirectusSDK 而不是 REST 或 GraphQL 吗?
- mysql - 在 Mac OS X 上安装 RMySQL 以在 Docker 中运行时出错
- python - 接收错误:_tkinter.TclError:无效的命令名称“.!frame3.!treeview”
- ios - 如何找到属于 Apple 框架的属性的默认值?
- json - Azure DevOps Server 2019 扩展:如何限制我的自定义页面出现的工作项数据输入表单?
- android - 布局对片段膨胀不起作用
- excel - 根据小数位数对列的值进行排序
- spring - 具有多分区分布式部署的 Apache Kafka
- html - Django 不接收 HTML 表单中的 POST 方法
- c++ - 为什么我无法使用索引访问字符串单个字符