Inheritance: ActiveRecordBase
Esempio n. 1
0
 public PostLazy(BlogLazy blog, String title, String contents, String category)
 {
     _blog = blog;
     _title = title;
     _contents = contents;
     _category = category;
 }
Esempio n. 2
0
 public PostLazy(BlogLazy blog, String title, String contents, String category)
 {
     _blog     = blog;
     _title    = title;
     _contents = contents;
     _category = category;
 }
        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);
        }
Esempio n. 5
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);
		}
Esempio n. 6
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 Get_with_lazy_classes_does_work()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(BlogLazy), typeof(PostLazy));
            Recreate();

            using (new SessionScope())
                new BlogLazy {
                    Author = "Mort", Name = "Hourglass"
                }.Create();

            using (new StatelessSessionScope())
            {
                Assert.AreEqual("Mort", BlogLazy.Find(1).Author);
                // The assert below cannot work, stateless sessions cannot serve proxies.
                // Assert.AreEqual(0, BlogLazy.Find(1).Posts.Count);
            }
        }
        public void Updating_stateless_fetched_entities_works()
        {
            InitializeLazy();

            using (new SessionScope())
                CreateLazyBlog();

            using (new StatelessSessionScope())
            {
                var blog = BlogLazy.Find(1);
                Assert.AreEqual("Hourglass", blog.Name);
                blog.Name = "HOURGLASS";
                blog.Update();
            }

            Assert.AreEqual("HOURGLASS", BlogLazy.Find(1).Name);
        }
        public void Can_delete_instances()
        {
            InitializeLazy();
            using (new SessionScope())
                CreateLazyBlog();

            var query = new SimpleQuery <BlogLazy>("from BlogLazy b where b.Author = ?", "Mort");

            using (new StatelessSessionScope())
            {
                foreach (var blog in query.Execute())
                {
                    blog.Delete();
                }
            }

            Assert.AreEqual(0, BlogLazy.FindAll().Length);
        }
        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);
		}