Skip to content

Instantly share code, notes, and snippets.

@codeimpossible
Created October 17, 2012 01:00
Show Gist options
  • Save codeimpossible/3903141 to your computer and use it in GitHub Desktop.
Save codeimpossible/3903141 to your computer and use it in GitHub Desktop.
PetaPoco Example
[PetaPoco.TableName("People")]
[PetaPoco.PrimaryKey("Id")]
public class Person
{
public int Id { get; set; }
// .. some other fields
}
public ActionResult Create( Person person )
{
var databaseContext = new PetaPoco.Database("QuantechConnectionString");
databaseContext.Insert( person );
return RedirectToAction("Index");
}
public ActionResult Update()
{
return View();
}
[HttpPost]
public ActionResult Update( int id, Person person )
{
var databaseContext = new PetaPoco.Database("QuantechConnectionString");
databaseContext.Update( person, id );
// if you don't have attributes on models then you have to:
databaseContext.Update("people", "id", person);
return RedirectToAction("Index");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment