简体   繁体   中英

entity framework inserting new entity

I am using the latest Entity Framework with a code-first approach. I have such classes:

[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; }
}

When I want to enter a new entry, I find the respective customer from the IDbSet<Customer> in my context and call

customer.Transactions.Add(newTrasnaction)
context.SaveChanges();

which gives me Invalid column name 'CustomerInitials' , which is a normal varchar column in the Customers table. Loading all data works just fine, just saving that has a problem.

Some additional details: When creating the new transaction, I don't set the Customer property, just CustomerId. Not sure if this is related to this problem or not.

Oh stupid me for not looking deeper into the exception. It came out there was an error an insert trigger for the table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM