I'm trying to use NPoco's Delete() method to delete a row from the database. However it just throws a NullReferenceException.
I have found a workaround, but I'm wondering if anyone knows why the built in delete function to delete by ID doesn't seem to work for me. This happens on multiple tables. All my tables have a standard integer primary key called ID, which has been flagged in the model using the [PrimaryKey("ID")]
decorator.
Object reference not set to an instance of an object.
Delete<PurchaseItem>(id); // throws null reference exception.
Delete<PurchaseItem>("where id = @0", id); // works.
The id being passed is valid an the item is in the database. The code does NOT get as far as executing any SQL.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
NPoco.PocoDataFactory.ForObject(Object o, String primaryKeyName) in d:\Adam\projects\NPoco\src\NPoco\PocoDataFactory.cs:41
NPoco.Database.Delete(String tableName, String primaryKeyName, Object poco, Object primaryKeyValue) in d:\Adam\projects\NPoco\src\NPoco\Database.cs:1587
NPoco.Database.Delete(Object pocoOrPrimaryKey) in d:\Adam\projects\NPoco\src\NPoco\Database.cs:1598
Harmsworth.DAL.HarmsworthDB.DeletePurchaseItemFromBasketByID(Int32 id) in c:\inetpub\wwwroot\harmsworth\Website\classes\HarmsworthDAL.cs:224
Harmsworth.ViewBasketPage.RemoveItem(Int32 id) in c:\inetpub\wwwroot\harmsworth\Website\view-basket.aspx.cs:187
Harmsworth.ViewBasketPage.PurchaseItemsRepeater_ItemCommand(Object sender, RepeaterCommandEventArgs e) in c:\inetpub\wwwroot\harmsworth\Website\view-basket.aspx.cs:75
System.Web.UI.WebControls.Repeater.OnItemCommand(RepeaterCommandEventArgs e) +111
[more redundant trace info]