Entityframework中的Sqlite,无法双倍调用SaveChanges

时间:2016-05-05 06:55:16

标签: c# entity-framework sqlite

这样的代码:

    using (TransactionScope ts = new TransactionScope())
    {
        DBContext context = new DBContext();
        SupEntity sup = new SupEntity();
        context.Set<SupEntity>().Add(sup);
        context.SaveChanges();
        CusEntity cus = new CusEntity();
        cus.Sup_ID = sup.Sup_ID; // sup.Sup_ID is autoincrement
        context.Set<CusEntity>().Add(cus);
        context.SaveChanges();  //throw exception in this line:database is locked\r\ndatabase is locked


        ts.Complete();
    }

似乎第二次调用SaveChanges方法时,上下文尝试与数据文件建立新连接,但数据文件已打开。 我怎样才能两次调用SaveChanges?

0 个答案:

没有答案