Hello, reading quickly the doc
"Constructs a new context instance using the existing connection to connect to a database. The connection will not be disposed when the context is disposed ifcontextOwnsConnection is false." base(existingConnection, false) { } Best Regards. On Thu, Feb 27, 2014 at 12:28 PM, Joe Strommen <joe.strom...@gmail.com>wrote: > The end of the using() block automatically closes the connection. If I > remove the line with "efContext.TestEntities.Count()" then it works fine. > > > On Thu, Feb 27, 2014 at 2:09 PM, mm.w <0xcafef...@gmail.com> wrote: > > > Hello, > > > > I don't know anything about c# and the Entity Framework, but something > > obvious where do you close your connection? > > > > Best Regards. > > > > > > On Wed, Feb 26, 2014 at 11:46 AM, Joe Strommen <joe.strom...@gmail.com > > >wrote: > > > > > Hi all, > > > I'm using SQLite with Entity Framework 6 and having a problem. I am > > > unable to delete the sqlite file, even though I'm disposing all my > > > disposable objects. Below is a minimal code sample that demonstrates > the > > > issue. I'd appreciate any advice/workarounds you can provide. I'm > happy > > > to enter a ticket for this, but I wanted to verify that I'm not doing > > > something wrong first. > > > > > > (I'm using the latest System.Data.SQLite NuGet package, which is > version > > > 1.0.91) > > > > > > Thanks > > > Joe Strommen > > > > > > class Program > > > { > > > public class TestContext : DbContext > > > { > > > public TestContext(DbConnection existingConnection) : > > > base(existingConnection, false) { } > > > > > > public DbSet<TestEntity> TestEntities { get; set; } > > > } > > > > > > public class TestEntity > > > { > > > public long Id { get; set; } > > > > > > public string Value { get; set; } > > > } > > > > > > static void Main(string[] args) > > > { > > > var path = "test.sqlite"; > > > if (File.Exists(path)) { File.Delete(path); } > > > using (var sqliteConnection = new SQLiteConnection("Data > > > Source=" + path)) > > > { > > > sqliteConnection.Open(); > > > > > > using (var sqliteCmd = > sqliteConnection.CreateCommand()) > > > { > > > sqliteCmd.CommandText = > > > "CREATE TABLE TestEntities (Id INTEGER PRIMARY > > KEY > > > AUTOINCREMENT, Value TEXT);" + > > > "INSERT INTO TestEntities ('Value') VALUES > > > ('Value1'), ('Value2'), ('Value3');"; > > > sqliteCmd.ExecuteNonQuery(); > > > } > > > > > > using (var efContext = new > TestContext(sqliteConnection)) > > > { > > > var entityCount = efContext.TestEntities.Count(); > > > } > > > } > > > File.Delete(path); // Fails; the file is still locked. > > > } > > > } > > > _______________________________________________ > > > sqlite-users mailing list > > > sqlite-users@sqlite.org > > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > > > _______________________________________________ > > sqlite-users mailing list > > sqlite-users@sqlite.org > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users