NPersistence - .NET Persistence API

Step 8 - Edit the Main method

You are here

  • Open the file 'Program.cs’, this file was created automatically by 'Microsoft Visual C#' when the project was created.
  • Insted of the current 'Main' method, add the following:
static void Main(string[] args)
{
    EntityManager em = PersistenceUtils.getEm();
    Employee jack = new Employee();
    jack.FirstName = "Jack";
    jack.LastName = "Bower";
    
    em.GetTransaction().Begin();
    em.Persist(jack);
    em.GetTransaction().Commit();
    
    Employee foundEmp = em.Find<Employee>(typeof(Employee), jack.ID);
    Console.WriteLine("Found <" + foundEmp.FirstName + " " + foundEmp.LastName + ">.");
}

The project is now ready. Click 'F5' to run it.