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 static IList<InteractiveMap> FindAllByQuery(string q) { string terms = QueryParser.BuildContainsTerms(q); SimpleQuery<InteractiveMap> query = new SimpleQuery<InteractiveMap>(QueryLanguage.Sql, String.Format(@" SELECT * FROM web_interactive_maps as interactive_map WHERE CONTAINS (interactive_map.title, '{0}') OR CONTAINS (interactive_map.abstract, '{0}')", terms ) ); query.AddSqlReturnDefinition(typeof(InteractiveMap), "interactive_map"); return query.Execute(); }
public void TestExpressionQuerySubProperty() { Blog blog = new Blog(); blog.Name = "hammett's blog"; blog.Author = "hamilton verissimo"; blog.Save(); Blog blog2 = new Blog(); blog2.Name = "hammett's blog other blog"; blog2.Author = "hamilton verissimo 2"; blog2.Save(); Post post1 = new Post(blog, "title1", "contents", "category1"); Post post2 = new Post(blog, "title2", "contents", "category2"); Post post3 = new Post(blog, "title3", "contents", "category3"); Post post21 = new Post(blog2, "title21", "contents", "category21"); Post post22 = new Post(blog2, "title22", "contents", "category22"); Post post23 = new Post(blog2, "title23", "contents", "category23"); post1.Save(); post2.Save(); post3.Save(); post21.Save(); post22.Save(); post23.Save(); //no idea how to make this style of query work. //Post[] posts = Post.FindAll( // Expression.Eq("Blog.Name", blog2.Name) // ); //Assert.IsTrue(posts.Length > 0); SimpleQuery<Post> q = new SimpleQuery<Post>(typeof(Post), "from Post p where p.Id = ? or p.Blog.Name = ?", 1, "hammett's blog other blog"); Post[] p = q.Execute(); Assert.IsTrue(p.Length > 0); }
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 Querying_works_with_HQL() { InitializeLazy(); using (new SessionScope()) CreateLazyBlog(); var query = new SimpleQuery<BlogLazy>("from BlogLazy b where b.Author = ?", "Mort"); using (new StatelessSessionScope()) Assert.AreEqual(1, query.Execute().Length); }
public void Nonlazy_collections_can_be_fetched_with_queries() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(SimpleBlog), typeof(SimplePost)); Recreate(); var blog = new SimpleBlog { Name = "Blog" }; var post = new SimplePost { Blog = blog, Title = "Post" }; blog.Save(); post.Save(); var query = new SimpleQuery<SimpleBlog>("from SimpleBlog b join fetch b.Posts"); using (new StatelessSessionScope()) { var result = query.Execute(); Assert.AreEqual(1, result.Length); Assert.AreEqual(1, result[0].Posts.Count); Assert.AreEqual("Post", result[0].Posts[0].Title); Assert.AreSame(result[0], result[0].Posts[0].Blog); } }