Skip to content

Instantly share code, notes, and snippets.

@greggnakamura
Forked from codeimpossible/peta_poco.cs
Created October 17, 2012 01:10
Show Gist options
  • Save greggnakamura/3903174 to your computer and use it in GitHub Desktop.
Save greggnakamura/3903174 to your computer and use it in GitHub Desktop.
MVC: 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