我有这些生成的类:
public partial class BookCategoryMapping
{
public int Id { get; set; }
public int CategoryPropertyId { get; set; }
public int GroupId { get; set; }
public string Value { get; set; }
public int OperatorId { get; set; }
public virtual CategoryProperties CategoryProperties { get; set; }
public virtual Group Group { get; set; }
public virtual Operator Operator { get; set; }
}
public partial class Operator
{
public Operator()
{
this.BookCategoryMapping = new HashSet<BookCategoryMapping>();
}
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<BookCategoryMapping> BookCategoryMapping { get; set; }
}
但每当我调用此方法时,使用update false。我得到了
无效的列名称'OperatorId'
public void SaveBookCategoryMapping(BookCategoryMapping bookCategoryMapping, bool update)
{
if (update)
_context.Entry(bookCategoryMapping).State = EntityState.Modified;
else
_context.BookCategoryMapping.Add(bookCategoryMapping);
_context.SaveChanges();
}
我不知道它是如何无效的,因为这两个类都是从EDMX模型生成的。
编辑:我已经尝试在SSMS中编写插入脚本。我承认专栏在这里。但插入仍然失败。答案 0 :(得分:0)
删除表格并重新创建它解决了问题。