Subsonic: Simple Repository - Update Crash

837 views Asked by At

Whenever I attempt to use a simple repository to simply update a record, I get an object reference not set to an instance of an object error. I suspect that I am doing something incorrect, can anyone see a problem with the below lines of code for saving data to subsonic?

I'm using .Net 3.5, SQL Server 2008 and Subsonic 3.0.

Thanks for any help.

        SimpleRepository repo = new SimpleRepository("Test", SimpleRepositoryOptions.RunMigrations);

        //Add the test object
        SimpleObject simple = new SimpleObject();
        simple.TestString = "Test";
        repo.Add(simple);

        Console.WriteLine(simple.TestString);

        //Reload the object and update it
        SimpleObject simpleReloaded = repo.Single<SimpleObject>(simple.ID);
        simpleReloaded.TestString = "Editted";
        repo.Update(simpleReloaded);//This line seems to crash repeatedly

        Console.WriteLine(repo.Single<SimpleObject>(simple.ID).TestString);
2

There are 2 answers

5
Adam Cooper On BEST ANSWER

My guess is that for some reason you're getting a new object on the line:

SimpleObject simpleReloaded = repo.Single<SimpleObject>(simple.ID);

So when you try and update it SubSonic is throwing an exception because simpleReloaded doesn't have a primary key. Try checking the value of simple.ID and then see if simpleReloaded is actually populated or whether you're just getting a new SimpleObject

EDIT: Looks like this is a bug try pulling the latest version from github

0
No Body On

get the daily build here, to address your issue (as Adam said above):

http://github.com/subsonic/SubSonic-3.0/tree/master

you need to compile to extract the SubSonic.Core.dll