Ninja Database Pro
Cannot find record of type
Troubleshooting > Cannot find record of type

Problem

Started trialing the software this afternoon. The sample works fine, but when I try it I get an error when saving my object.


Exception = "Cannot find record of type Person with primary key 1."

My code looks like this:

NinjaDbPro db = new NinjaDbPro("TabletDir""TabletDB");
        
db.OpenDatabase();

Person person = new Person();
        person.PK = 1;
        person.Name = "Damien";
        db.Save(person); <= ERROR OCCURS HERE
Class is defined as:
public class Person
    {
      [PrimaryKey]
      public int PK { getset; }

      public string Name { getset; }
    }

Answer

The problem is you are trying to perform an update, not an insert.  By setting the value of the primary key to 1, it is considered an update.  Ninja Database Pro will automatically do an auto increment primary key.  Don't set the primary key.


NinjaDbPro db = new NinjaDbPro("TabletDir", "TabletDB");
db.OpenDatabase();

Person person = new Person();
person.Name = "Damien";
db.Save(person);