Sql – Subsonic 3.0.0.5 Migration Row Update

sql serversubsonicsubsonic3

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

Best Answer

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.Update[T](T item)

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

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

My configuration: SubSonic 3, SQLite, empty database