我想将我的模型插入数据库
EventAdditionalSell eas = new EventAdditionalSell();
eas.EventNoteID = en.EventID; (e.g 100 which exists in datatable)
eas.Person = mdl.Person; (string - can be just "")
db.EventAdditionalSells.Add(eas);
db.SaveChanges();
我总是得到一个例外
无法将值NULL插入到'EventAdditionalSellID'列中,表'1028_test.dbo.EventAdditionalSells';列不允许空值。 INSERT失败。
我的课程:
public class EventAdditionalSell
{
[Key]
public int EventAdditionalSellID { get; set; }
[Display(Name = "Kupujący")]
public string Person { get; set; }
public int EventNoteID { get; set; }
public virtual EventNote EventNote { get; set; }
public virtual List<PaintballItem> PaintballItems { get; set; }
}
这里有什么问题?