private static void CreateEmployeeAndSave() { var tobin = new Employee { Name = "Tobin Harris" }; using (var session = OpenSession()) { using (var transaction = session.BeginTransaction()) { session.Save(tobin); transaction.Commit(); } } }
static void CreateEmployeeAndSaveToDatabase() { Employee tobin = new Employee(); tobin.name = "Tobin Harris"; using (ISession session = OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(tobin); transaction.Commit(); } Console.WriteLine("Saved Tobin to the database"); } }
private static void UpdateTobinAndAssignPierre() { using (var session = OpenSession()) { using (var transaction = session.BeginTransaction()) { var query = session.CreateQuery("from Employee where Name='Tobin Harris'"); var tobin = query.List<Employee>()[0]; tobin.Name = "Tobin David Harris"; var pierre = new Employee {Name = "Pierre Henri Kuate"}; tobin.Manager = pierre; transaction.Commit(); Console.WriteLine("Updated Tobin and added Pierre"); } } }
static void UpdateTobinAndAssignPierreHenriAsManager() { using (ISession session = OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { IQuery q = session.CreateQuery( "from Employee where name = 'Tobin Harris'"); Employee tobin = q.List<Employee>()[0]; tobin.name = "Tobin David Harris"; Employee pierreHenri = new Employee(); pierreHenri.name = "Pierre Henri Kuate"; tobin.manager = pierreHenri; transaction.Commit(); Console.WriteLine("Updated Tobin and added Pierre Henri"); } } }