VS2008,Cannot add an entity with a key that is already in use.
使用VS2008,LINQ方式使现对数据库的操作,在对大批对象进行操作时,出现下列问题:
自己写了一个方法对Ticket对象进行批增加,最后执行到m_dataContext.SubmitChanges();方法时提示DuplicateKeyException was unhandled by user code. Cannot add an entity with a key that is already in use.
public void Add(IList<Ticket> tickets)
{
m_dataContext.Tickets.InsertAllOnSubmit(tickets);
m_dataContext.SubmitChanges();
}
其中ticket是数据库表中映射出来的对象,而tickets封装有多个ticket对象,请高手指点这是怎么回事,谢谢!