public void Collections_can_be_fetched_with_queries()
        {
            InitializeLazy();

            var blog = new BlogLazy {
                Author = "Mort", Name = "Hourglass"
            };
            var post = new PostLazy {
                Blog = blog, Title = "...", Created = DateTime.Now
            };

            blog.Save();
            post.Save();

            var query = new SimpleQuery <BlogLazy>("from BlogLazy b join fetch b.Posts");

            using (new StatelessSessionScope())
            {
                var result = query.Execute();
                Assert.AreEqual(1, result.Length);
                Assert.AreEqual(1, result[0].Posts.Count);
                var queriedPost = result[0].Posts[0] as PostLazy;
                Assert.AreEqual("...", queriedPost.Title);
            }
        }
        public void MixingSessionScopeAndTransactionScopes3()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(PostLazy), typeof(BlogLazy));
            Recreate();

            PostLazy.DeleteAll();
            BlogLazy.DeleteAll();

            BlogLazy b = new BlogLazy();

            using (new SessionScope())
            {
                b.Name   = "a";
                b.Author = "x";
                b.Save();

                using (new TransactionScope())
                {
                    for (int i = 1; i <= 10; i++)
                    {
                        PostLazy post = new PostLazy(b, "t", "c", "General");
                        post.Save();
                    }
                }
            }

            using (new SessionScope())
            {
                // We should load this outside the transaction scope

                b = BlogLazy.Find(b.Id);

                using (TransactionScope transaction = new TransactionScope())
                {
                    int total = b.Posts.Count;

                    foreach (PostLazy p in b.Posts)
                    {
                        p.Delete();
                    }

                    b.Delete();

                    transaction.VoteRollBack();
                }
            }

            BlogLazy[] blogs = BlogLazy.FindAll();
            Assert.AreEqual(1, blogs.Length);

            PostLazy[] posts = PostLazy.FindAll();
            Assert.AreEqual(10, posts.Length);
        }
Exemplo n.º 3
0
		public void CanSaveAndLoadLazyEntityOutsideOfScope()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(),
				   typeof(BlogLazy), typeof(PostLazy));
			Recreate();
			BlogLazy blog = new BlogLazy();
			blog.Save();
			PostLazy post = new PostLazy(blog, "a", "b", "c");
			post.Save();

			PostLazy postFromDb = PostLazy.Find(post.Id);
			Assert.AreEqual("a", postFromDb.Title);
		}
Exemplo n.º 4
0
        public void CanSaveAndLoadLazyEntityOutsideOfScope()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(),
                                           typeof(BlogLazy), typeof(PostLazy));
            Recreate();
            BlogLazy blog = new BlogLazy();

            blog.Save();
            PostLazy post = new PostLazy(blog, "a", "b", "c");

            post.Save();

            PostLazy postFromDb = PostLazy.Find(post.Id);

            Assert.AreEqual("a", postFromDb.Title);
        }
        public void Collections_can_be_fetched_with_queries()
        {
            InitializeLazy();

            var blog = new BlogLazy { Author = "Mort", Name = "Hourglass" };
            var post = new PostLazy { Blog = blog, Title = "...", Created = DateTime.Now };

            blog.Save();
            post.Save();

            var query = new SimpleQuery<BlogLazy>("from BlogLazy b join fetch b.Posts");

            using (new StatelessSessionScope())
            {
                var result = query.Execute();
                Assert.AreEqual(1, result.Length);
                Assert.AreEqual(1, result[0].Posts.Count);
                var queriedPost = result[0].Posts[0] as PostLazy;
                Assert.AreEqual("...", queriedPost.Title);
            }
        }
		public void MixingSessionScopeAndTransactionScopes3()
		{
			ActiveRecordStarter.Initialize(GetConfigSource(), typeof(PostLazy), typeof(BlogLazy));
			Recreate();

			PostLazy.DeleteAll();
			BlogLazy.DeleteAll();

			BlogLazy b = new BlogLazy();

			using(new SessionScope())
			{
				b.Name = "a";
				b.Author = "x";
				b.Save();

				using(new TransactionScope())
				{
					for(int i = 1; i <= 10; i++)
					{
						PostLazy post = new PostLazy(b, "t", "c", "General");
						post.Save();
					}
				}
			}

			using(new SessionScope())
			{
				// We should load this outside the transaction scope

				b = BlogLazy.Find(b.Id);

				using(TransactionScope transaction = new TransactionScope())
				{
					int total = b.Posts.Count;

					foreach(PostLazy p in b.Posts)
					{
						p.Delete();
					}

					b.Delete();

					transaction.VoteRollBack();
				}
			}

			BlogLazy[] blogs = BlogLazy.FindAll();
			Assert.AreEqual(1, blogs.Length);

			PostLazy[] posts = PostLazy.FindAll();
			Assert.AreEqual(10, posts.Length);
		}