-
-
Save greggnakamura/3903174 to your computer and use it in GitHub Desktop.
MVC: PetaPoco Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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