views:

223

answers:

1

Before I invest the time in modifying the SubSonic 3 source, I figured I ask to see if I'm missing something simple.

Is it possible to use the SubSonic 3 Repository with migrations on a SQLite In-Memory database? I couldn't find a way to force the DbDataProvider to keep the connection open so the In-Memory SQLite database doesn't vanish when the connection get's closed.

The unit test with the connection string I was trying is...

public class SQLite_InMemory_SimpleRepositoryTests
{
    public class Job
    {
        public Guid JobId { get; set; }
        public string JobName { get; set; }
    }

    [Fact]
    public void SQLite_InMemory_SimpleRepo_CanStayOpen()
    {
        IDataProvider provider = ProviderFactory.GetProvider("Data Source=:memory:;Version=3;New=True;Pooling=True;Max Pool Size=1;", "System.Data.SQLite");
        IRepository repository = new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations);

        for (int i = 0; i < 10000; i++)
        {
            var job = new Job {JobId = Guid.NewGuid(), JobName = "Job_"+i};
            repository.Add(job);
        }
    }
}

I tried setting the "Shared Connection" on the IDataProvider, but the connection still seemed to close.

If not, I'll update the SubSonic source, and submit the changes.

Thanks!

+2  A: 

Interesting - no there's no way that I can think of to do this other than maybe creating a static IDataProvider but even then we close off the connection for doing things like executing scalar's etc.

I spose you could create such a thing by implementing the IDataProvider then setting things up as you need - all the execution goes through it. But this is making me wonder if we explicitly shut things down in the calling code - which would be bad design on my part... hmmm.\

Would love to have this feature...

Rob Conery
Hi Rob, thanks for the info. I did a trace on the execution and it's calling Close and Dispose in a few places. I was going to implement an extension method on the IDataProvider called bool IsSqlLiteMemoryDb() that would check the connection type and :memory: in the connection string and override the disposes/closes. Where should a post the code?
Steve Foster
Also, just to note, I was able to get the test to pass, but 'hackishly'. I'm going to refactor the code, and post it. Just let me know where. Thanks.
Steve Foster
I would presume here?: http://github.com/subsonic/SubSonic-3.0
Mike
Thanks Mike, I'll branch and post.
Steve Foster