views:

266

answers:

4

Hi, I want to update a table row and I have a following Code

void updatePrimaryPaymentAndSecondaryPaymentSourceTypes()

{

LookUpDetails lookUpDetail = new LookUpDetails();

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

lookUpDetail = repo.Single(80);

lookUpDetail.Col1Value = "My Checking Account";

repo.Update(lookUpDetail);

}

public class LookUpDetails

{

[SubSonicPrimaryKey]

public int LookUpDetailId {get; set;}

public int LookUpGroupId { get; set; }

public string Code { get; set; }

public int SortOrder { get; set; }

public string Col1Value { get; set; }

[SubSonicNullString]

public string Col2Value { get; set; }

[SubSonicNullString]

public string Col3Value { get; set; }

[SubSonicNullString]

public string Col4Value { get; set; }

[SubSonicNullString]
public string Col5Value { get; set; }

public DateTime  CreatedOn { get; set; }

public string CreatedBy { get; set; }

public DateTime ModifiedOn { get; set; }

public string ModifiedBy { get; set; }

public Boolean IsActive { get; set; }

}

When I execute then repo.Update(lookUpDetail); shows me Null reference Exception. Can you please tell me How I will be able to update a single record in a table?

Regards

A: 

did you ever fix this? I'm having the same problem, get null reference when running update method... neither repository nor the object being updated are null...

A: 

I have the very same problem with very simple model class:

class Person
{
    public long ID {get;set;} 
    public string Name { get; set;}
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection) {
    Person toUpdate = Repository.All<Person>().Single(p => p.ID == id);
    TryUpdateModel(toUpdate, collection.ToValueProvider());
    Repository.Update(toUpdate); //throws nullreferenceexception
    return RedirectToAction("Index");
}

stack trace:

at SubSonic.Query.Update.GetCommand()

at SubSonic.Query.Update.Execute()

at SubSonic.Repository.SimpleRepository.UpdateT

at MvcApplication1.Controllers.PersonController.Edit(Int32 id, FormCollection collection)

in H:\...\Controllers\PersonController.cs:line 71"

My configuration: SubSonic 3, SQLite, empty database

Marek
+1  A: 

This issue may be fixed in the trunk by now, but the fix is documented here if you would rather just patch up your current source code.

bonder
A: 

I ran into this problem as well and I was able to download the latest SubSonic source and the issue was already fixed. Just open the SubSonic.Core project and do a build and replace your project's reference to SubSonic.Core.

Download Latest Source http://github.com/subsonic/SubSonic-3.0

Boom - Repository Update works again!

Danny Douglass