插入时实体框架出错

时间:2015-03-16 06:10:35

标签: c# entity-framework

我在插入时在Entity Framework中收到此错误。更新条目时发生错误。

这是我的代码:

 public static void NewCustomer(string name,string address,string cnicno, string cellno,int productpurchasedid,string comments  )
 {
   using (CRMEntities context = new CRMEntities())
   { 
     Customer cs = new Customer() { name=name , address=address , cnicno = cnicno, cellno =cellno, productpurchasedid = productpurchasedid, comments=comments };
     context.Customers.Add(cs);
     context.SaveChanges();       //Error point
   }
 }

1 个答案:

答案 0 :(得分:0)

尝试检查数据库表中的ID列是否将Identity设置为true。如果没有,请将其设置为true。

相关问题