Hi guys, i'm starting with petapoco to save my categories, buy im having a problem with the autoincrement,
I followed this example: http://www.nibble.be/?p=440, but i dont create nodes with the categories, i show them in a table, loading them from the DB, and everyone have Id = 0
This is my model:
[TableName("categories")] [PrimaryKey("CategoryId", autoIncrement = true)] public class Category { public Category() { } [PrimaryKeyColumn(AutoIncrement = true)] public int CategoryId { get; set; } public string Name { get; set; } public string Father { get; set; } public override string ToString() { return "Category: "+ Name ; }
This is my RegisterEvents
public class RegisterEvents : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { var db = applicationContext.DatabaseContext.Database; if (!db.TableExist("categories")) { db.CreateTable(false); } } }
And the controller:
public class CategoryApiController : UmbracoApiController { public IEnumerable GetAll() { var query = new Sql().Select("*").From("categories"); return DatabaseContext.Database.Fetch(query); } public Category GetById(int id) { var query = new Sql().Select("*").From("categories").Where(x => x.CategoryId == id); return DatabaseContext.Database.Fetch(query).FirstOrDefault(); } public Category PostSave(Category cat) { if (cat.CategoryId > 0) DatabaseContext.Database.Update(cat); else DatabaseContext.Database.Save(cat); return cat; } public int DeleteById(int id) { return DatabaseContext.Database.Delete(id); } }
i don't see where is the error, but i can't edit or delete items, because them all have the same id
Problems with petapoco
Hi guys, i'm starting with petapoco to save my categories, buy im having a problem with the autoincrement,
I followed this example: http://www.nibble.be/?p=440, but i dont create nodes with the categories, i show them in a table, loading them from the DB, and everyone have Id = 0
This is my model:
This is my RegisterEvents
And the controller:
i don't see where is the error, but i can't edit or delete items, because them all have the same id
Same here, how did you solve this?
is working on a reply...