Repository.Flush C# (CSharp) Method

Flush() public method

Method for flushing the session.
public Flush ( ) : void
return void
        public void Flush()
        {
            Reconnect(_session);
            try
            {
                _session.Flush();
                _session.Clear();
            }
            finally
            {
                Disconnect(_session);
            }
        }
        /// <summary>

Usage Example

        public void GetAccountsByCustomerSomeAccountsFound()
        {
            IAccountRepository accountRepository = new AccountRepository(NhibernateHelper.SessionFactory);
            Repository repository = new Repository(NhibernateHelper.SessionFactory);

            Customer thirdParty1 = new Customer { Code = "tjdsklfs", Email = "*****@*****.**", LastName = "roux", FirstName = "Olivier", Password = "******", PasswordSalt = "sss" };
            Customer thirdParty2 = new Customer { Code = "topsecret", Email = "*****@*****.**", LastName = "roux2", FirstName = "Olivier", Password = "******", PasswordSalt = "sss" };

            Account account1 = new Account { Balance = 201, BalanceDate = DateTime.Now, Number = "dsf1", Iban="12354"};
            Account account2 = new Account { Balance = 202, BalanceDate = DateTime.Now, Number = "dsf2", Iban="12435"};

            Role role = new Role{Id=1};
            thirdParty1.RelatedAccounts.Add(account1, role);
            thirdParty1.RelatedAccounts.Add(account2, role);

            using (NhibernateHelper.SessionFactory.GetCurrentSession().BeginTransaction())
            {
                repository.Save(thirdParty1);
                repository.Save(thirdParty2);
                repository.Save(account1);
                repository.Save(account2);

                repository.Flush();

                IList<Account> accounts = accountRepository.GetAccountsByCustomer(thirdParty1.Id);
                Assert.AreEqual(2, accounts.Count);
            }
        }
All Usage Examples Of Repository::Flush