public void CleanAllEntities() { using (var tx = new TransactionScope(TransactionScopeOption.RequiresNew)) using (var nhSession = _sessionFactory.OpenSession()) { nhSession.CreateQuery("delete CUSTIS.I18N.SampleDomainModel.Product").ExecuteUpdate(); tx.Complete(); } }
public void TestParameters() { var query = sessionFactory.OpenSession().CreateQuery("FROM Code WHERE Name = :a or Name = :b or Name = :c"); var list = query.NamedParameters; foreach (var param in list) { Console.WriteLine(param); } Console.WriteLine(DateTime.Now.Ticks); }
public Reminders() { InitializeComponent(); if (mySession != null && mySession.IsOpen) { mySession.Close(); } if (mySessionFactory != null && !mySessionFactory.IsClosed) { mySessionFactory.Close(); } // Initializing NHibernate myConfiguration = new Configuration(); myConfiguration.Configure(); mySessionFactory = myConfiguration.BuildSessionFactory(); mySession = mySessionFactory.OpenSession(); //Show TaskNameFromDatabase in ListBox using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria <ToDo>(); IList <ToDo> list = criteria.List <ToDo>().Where(a => a.Status == "ToDo" && (DateTime.Now < a.StartDate)) .OrderBy(a => a.StartDate).OrderBy(a => a.EndDate).ToList(); foreach (var item in list) { listView_reminders.Items.Add(item.TaskName); listView_reminders.Items.Add(item.StartDate.ToString("dd/MM/yyyy")); listView_reminders.Items.Add(item.EndDate.ToString("dd/MM/yyyy")); } } ChangeView(); }
public GroupingControlForm(NHibernate.ISessionFactory sessionFactory) { InitializeComponent(); this.session = sessionFactory.OpenSession(); tlvGroupedFiles.CanExpandGetter += x => (((tlvBranch)x).Data is SpectrumSourceGroup && ((tlvBranch)x).Children.Any()); tlvGroupedFiles.ChildrenGetter += getChildren; tlvGroups.AspectGetter += x => { var nodeTracker = ((tlvBranch)x); var offsetCorrection = 0; while (nodeTracker.Parent.Text != null) { offsetCorrection++; nodeTracker = nodeTracker.Parent; } return(((tlvBranch)x).Text + new string(' ', offsetCorrection *7)); }; tlvGroups.AutoCompleteEditor = false; tlvGroups.ImageGetter += delegate(object x) { return((((tlvBranch)x).Data is SpectrumSourceGroup) ? Properties.Resources.XPfolder_closed : Properties.Resources.file); }; ApplyDefaultGroups(null, null); }
internal NHibernate.ISession CreateSession() { lock (this) { _currentSession = _sessionFactory.OpenSession(); } return(_currentSession); }
public static ISession GetCurrentSession() { if (currentSession == null) { currentSession = _sessionFactory.OpenSession(); } return(currentSession); }
//delete from database private void button_deleteTask_Click(object sender, EventArgs e) { using (ISession session = mySessionFactory.OpenSession()) { SqlConnection con = session.Connection as SqlConnection; SqlCommand cmd = new SqlCommand($"Delete from ToDo where Id={id}", con); cmd.ExecuteNonQuery(); } this.Close(); }
/// <summary> /// Gets the unit of work. /// </summary> /// <returns></returns> private IUnitOfWork GetUnitOfWork() { var cfg = new Configuration(); cfg.Configure(); cfg.AddAssembly(Assembly.Load("CRM.Dal.Nhibernate")); NHibernate.ISessionFactory factory = cfg.BuildSessionFactory(); ISession session = factory.OpenSession(); return(new UnitOfWork(session)); }
public IsobaricMappingForm(NHibernate.ISessionFactory sessionFactory) { InitializeComponent(); this.session = sessionFactory.OpenSession(); acStrings = new AutoCompleteStringCollection(); acStrings.Add("Reference"); acStrings.Add("Empty"); isobaricMappingTables = new Dictionary <QuantitationMethod, DataGridView>(); }
public void InitializingHibernate() { if (mySession != null && mySession.IsOpen) { mySession.Close(); } if (mySessionFactory != null && !mySessionFactory.IsClosed) { mySessionFactory.Close(); } myConfiguration = new Configuration(); myConfiguration.Configure(); mySessionFactory = myConfiguration.BuildSessionFactory(); mySession = mySessionFactory.OpenSession(); }
public void reminder() { DateTime date = DateTime.Now; DateTime date_plusOne = date.AddDays(1); if (mySession != null && mySession.IsOpen) { mySession.Close(); } if (mySessionFactory != null && !mySessionFactory.IsClosed) { mySessionFactory.Close(); } // Initializing NHibernate myConfiguration = new Configuration(); myConfiguration.Configure(); mySessionFactory = myConfiguration.BuildSessionFactory(); mySession = mySessionFactory.OpenSession(); int i = 0; //I'm checking if there are any new tasks tomorrow using (mySession.BeginTransaction()) { ICriteria criteria = mySession.CreateCriteria <ToDo>(); IList <ToDo> list = criteria.List <ToDo>().Where(a => a.Status == "ToDo" && (date <= a.StartDate && date_plusOne >= a.StartDate)).ToList(); i = 0; foreach (var item in list) { i++; } } if (i > 0) { Alert alert = new Alert(); alert.showAlert("Jutro masz nowe zadania do zrobienia !"); } button_TodoList.Text = "Rzeczy \ndo zrobienia"; }
/// <summary> /// Opens database connection and begins transaction. /// </summary> public void BeginTransaction() { Session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(Session); _transaction = Session.BeginTransaction(); }
public static void OpenSession() { HttpContext.Current.Items[SessionKey] = _sessionFactory.OpenSession(); }
public virtual void openConnection() { Session = sessionFactory.OpenSession(); }
public ITransaction Create(ITransaction parent) { var session = _sessionFactory.OpenSession(); return(new NHTransaction(session, parent)); }
private IUnitOfWork GetUnitOfWork() { ISession session = _sessionFactory.OpenSession(); return(new UnitOfWork(session)); }
public UnitOfWork(NHibernate.ISessionFactory sessionFactory) { _sessionFactory = sessionFactory; Session = _sessionFactory.OpenSession(); _transaction = Session.BeginTransaction(); }