mercredi 4 mai 2016

Sqlite in Entityframework,Can't invoke SaveChanges double times

The code like this:

    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();
    }

It seems like that when the SaveChanges method been invoked second time,the context try to make an new connection to the data file,but the data file was opened. How can I invoke SaveChanges two times?

Aucun commentaire:

Enregistrer un commentaire