问题描述
public string fruitType = "Apple";
public string FruitType
{
get { return fruitType; }
set { fruitType = value; }
}
但是,我遇到的问题是FruitType
不是数据库表中的列,因此它引发了错误。即使该列不存在,我是否可以设置它?
解决方法
将您的媒体资源标记为NotMapped
,并使用默认值:
public string fruitType = "Apple";
[NotMapped]
public string FruitType
{
get { return fruitType; }
set { fruitType = value ?? fruitType; }
}