Expression based queries in the PFS

Update (2009.03.27): From Sense/Net 6.0 Beta 3 Portal File System (PFS) is called Sense/Net Content Repository (SNCR) 

Our apple of the eye PFS is getting smarter and smarter every day. Beyond its capabilities in storing typed information in an arbitrary object tree or graph, PFS also provides (or under the way to start providing :)  a wealth of tools to create and execute queries at runtime against the datastore. While we have PortalFileSystem.Search namespace at hand with its QueryExpression class, developers using the Microsoft .NET Framework 3.5 will also want to utilize our declarative, strongly typed query API. And by this fall we will have the LinqToPFS provider to support standard query operations with sql like syntax.

(This short writing is by no means wants to be a complete documentation on how to build queries against the PFS. That will come in a later entry - I promise. Now it's more like an apatizer to develop your hunger - or if this would already be the case then a small chunk of meat to keep you from starvation).

In our example query scenario we will search for a User object with a given name under a specified part of our object tree. (As you might already guess in the PFS every single information entity is stored as a Node or a subclass of a Node. This covers folders, files, images, even users - you name it.)

1) Using PortalFileSystem.Search

            NodeQuery query = new NodeQuery();
            ExpressionList expressionList = new ExpressionList(ChainOperator.And);
            expressionList.Add(new TypeExpression(ActiveSchema.NodeTypes["User"], true));
            expressionList.Add(new StringExpression(StringAttribute.Path, StringOperator.StartsWith, "/Root/Intranet/Users"));
            expressionList.Add(new StringExpression(StringAttribute.Name, StringOperator.Equal, "Name"));
            NodeList<Node> result = query.Execute();
            User user = result[0] as User;

2) Using Qry #1

            var qry = Portal.Root.CreateQuery<Node>();
            qry &= node => node is User;
            qry &= node => node.Path.StartsWith("/Root/Intranet/Users");
            qry &= node => node.Name == "Name";
            User u = qry.Execute()[0] as User;

As you can see this form is more concise plus frees you from learning our QueryExpression syntax - for the cost of the .NET 3.5 being a runtime requirement.

3) Using Qry #2

            var qry = Portal.Root.CreateQuery<User>();
            qry &= node => node.Path.StartsWith("/Root/Intranet/Users");
            qry &= node => node.Name == "Name";
            User u = qry.Execute()[0];

4) Using Qry #3

            var UsersFolder = Node.Load("/Root/Intranet/Users");
            var qry = UsersFolder.AllChildren.CreateQuery<User>();
            qry &= node => node.Name == "Name";
            User u = qry.Execute()[0];

5) Using LinqToPFS  - "blue print version"

            var userquery = from u in Portal.Root.Children<User>
                                    where u.Name == "Name" and u.Path.StartWith("/Root/Intranet/Users")
                                    select u;
            User user = userquery.First();


Comments are closed

Welcome to the blog!

Sense/Net ECM is ever evolving. Community means the world to us so we want to keep you apprised on what’s happening on our side of the woods. Want to make us happy? Add a comment and tell us what you think!

Month List