C# 实体框架插入新实体

C# 实体框架插入新实体,c#,foreign-keys,data-annotations,entity-framework-5,C#,Foreign Keys,Data Annotations,Entity Framework 5,我使用最新的实体框架,采用代码优先的方法。 我有这样的课程: [Serializable] public class Customer { [Key] public int Id { get; set; } public string CustomerInitials { get; set; } [InverseProperty("Customer")] public virtual List<Transact

我使用最新的实体框架,采用代码优先的方法。 我有这样的课程:

[Serializable]
public class Customer
{
        [Key]
        public int Id { get; set; }
        public string CustomerInitials { get; set; }
        [InverseProperty("Customer")]
        public virtual List<Transaction> Transactions { get; set; }
}

[Serializable]
public class Transaction
{
        [Key]
        public int Id { get; set; }
        public int CustomerId { get; set; }
        [InverseProperty("Transactions")]
        public virtual Customer Customer { get; set; }
}
这给了我
无效的列名“CustomerInitials”
,这是
Customers
表中的一个普通varchar列。加载所有数据工作正常,只是保存有问题


一些其他详细信息:创建新交易时,我不设置Customer属性,只设置CustomerId。不确定这是否与此问题有关。

哦,我太傻了,没有深入研究异常。结果显示表的insert触发器出错。

我觉得一切正常,您是否100%确定Customer在DB中有“CustomerInitials”列?
customer.Transactions.Add(newTrasnaction)
context.SaveChanges();