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

Reply via email to