コード例 #1
0
 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();
         }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        internal NHibernate.ISession CreateSession()
        {
            lock (this)
            {
                _currentSession = _sessionFactory.OpenSession();
            }

            return(_currentSession);
        }
コード例 #6
0
        public static ISession GetCurrentSession()
        {
            if (currentSession == null)
            {
                currentSession = _sessionFactory.OpenSession();
            }

            return(currentSession);
        }
コード例 #7
0
 //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();
 }
コード例 #8
0
        /// <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));
        }
コード例 #9
0
ファイル: IsobaricMappingForm.cs プロジェクト: zrolfs/pwiz
        public IsobaricMappingForm(NHibernate.ISessionFactory sessionFactory)
        {
            InitializeComponent();

            this.session = sessionFactory.OpenSession();

            acStrings = new AutoCompleteStringCollection();
            acStrings.Add("Reference");
            acStrings.Add("Empty");

            isobaricMappingTables = new Dictionary <QuantitationMethod, DataGridView>();
        }
コード例 #10
0
 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();
 }
コード例 #11
0
        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";
        }
コード例 #12
0
 /// <summary>
 /// Opens database connection and begins transaction.
 /// </summary>
 public void BeginTransaction()
 {
     Session = _sessionFactory.OpenSession();
     CurrentSessionContext.Bind(Session);
     _transaction = Session.BeginTransaction();
 }
コード例 #13
0
ファイル: Database.cs プロジェクト: Husnainakmal5/BlogCMS
 public static void OpenSession()
 {
     HttpContext.Current.Items[SessionKey] = _sessionFactory.OpenSession();
 }
コード例 #14
0
 public virtual void openConnection()
 {
     Session = sessionFactory.OpenSession();
 }
コード例 #15
0
        public ITransaction Create(ITransaction parent)
        {
            var session = _sessionFactory.OpenSession();

            return(new NHTransaction(session, parent));
        }
コード例 #16
0
ファイル: SessionPorvider.cs プロジェクト: alexnec37/testTask
        private IUnitOfWork GetUnitOfWork()
        {
            ISession session = _sessionFactory.OpenSession();

            return(new UnitOfWork(session));
        }
コード例 #17
0
ファイル: UnitOfWork.cs プロジェクト: nicholaspei/DevText
 public UnitOfWork(NHibernate.ISessionFactory sessionFactory)
 {
     _sessionFactory = sessionFactory;
     Session = _sessionFactory.OpenSession();
     _transaction = Session.BeginTransaction();
 }