예제 #1
0
        public void Can_Init_NHibernate_Session()
        {
            var session = NHibernateSession.Current;

            using (var trans = session.BeginTransaction())
            {
                var result = session.QueryOver<Category>().List();
                var item1 = result.FirstOrDefault();

                var news = new News { Title = "Title 2", ShortDescription = "Sort description 1", Content = "Content 1" };

                var poll = new Poll { Value = 1, WhoVote = "ThangChung", VoteDate = DateTime.Now };

                var user = new User { UserName = "******", Password = "******" };

                news.AssignCategory(item1);

                news.AssignPoll(poll);

                user.AssignPoll(poll);

                session.Save(news);

                session.Save(poll);

                session.Save(user);

                session.Flush();
            }
        }
예제 #2
0
        public void Can_Init_NHibernate_Session()
        {
            var session = NHibernateSession.Current;

            using (var trans = session.BeginTransaction())
            {
                var result = session.QueryOver <Category>().List();
                var item1  = result.FirstOrDefault();

                var news = new News {
                    Title = "Title 2", ShortDescription = "Sort description 1", Content = "Content 1"
                };

                var poll = new Poll {
                    Value = 1, WhoVote = "ThangChung", VoteDate = DateTime.Now
                };

                var user = new User {
                    UserName = "******", Password = "******"
                };

                news.AssignCategory(item1);

                news.AssignPoll(poll);

                user.AssignPoll(poll);

                session.Save(news);

                session.Save(poll);

                session.Save(user);

                session.Flush();
            }
        }
예제 #3
0
        public void InitData()
        {
            _category = new Category
                            {
                                Name = "test name",
                                CreatedDate = DateTime.Now,
                                Description = "test description"
                            };
            _news = new News
                        {
                            Title = "test title",
                            ShortDescription = "test short description",
                            Content = "test content"
                        };
            _poll = new Poll
                        {
                            Value = 0,
                            VoteDate = DateTime.Now,
                            WhoVote = "test user"
                        };
            _user = new User
                        {
                            UserName = "******",
                            Password = "******",
                            Address = new Address("street", "ward", "district")
                        };

            // --------------------------------

            _poll.AssignUser(_user);
            _user.AssignPoll(_poll);
            _poll.AssignNews(_news);
            _news.AssignPoll(_poll);
            _category.AssignNews(_news);

            using (var uow = IoC.GetInstance<IUnitOfWork>())
            {
                uow.Session.SaveOrUpdate(_category);
                uow.Session.SaveOrUpdate(_news);
                uow.Session.SaveOrUpdate(_poll);
                uow.Session.SaveOrUpdate(_user);

                // --------------------------------

                //var result = uow.Session.QueryOver<News>()
                //    .Where(x => x.Id == 1)
                //    .List();

                //var poll = uow.Session.QueryOver<Poll>()
                //    .Where(x => x.Id == 1)
                //    .List();
                ////result.FirstOrDefault().AssignPoll(_poll);
                ////_poll.AssignNews(result.FirstOrDefault());
                ////uow.Session.Save(result.FirstOrDefault());
                ////uow.Session.Save(_poll);

                // --------------------------------

                uow.Commit();
            }
        }