Example #1
0
        public void SameEntityLoadedFromTwoDifferentSessionsMatches()
        {
            var config = new DatabaseConfigurationForSqlServer();

            object id        = 0;
            var    employee1 = new Employee
            {
                EmployeeNumber = "123456789",
                DateOfBirth    = new DateTime(1980, 2, 23),
                DateOfJoining  = new DateTime(2012, 3, 15)
            };

            using (var session = config.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    id = session.Save(employee1);
                    transaction.Commit();
                }
            }

            Employee employee2 = null;

            using (var session = config.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    employee2 = session.Get <Employee>(id);
                    transaction.Commit();
                }
            }

            Assert.That(employee1.Equals(employee2));
        }
Example #2
0
        public void Sample()
        {
            var config = new DatabaseConfigurationForSqlServer();

            using (var session = config.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    try
                    {
                        //Database operations here
                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                    }
                }
            }
        }