| « EUSS | My SVN & TortoiseSVN experience » |
Querying over objects: just say "EON"
Evaluant OPath Navigator (Eon)
This is a new library I made to allow any .Net programmer to be able to query any in-memory object graph using an OPath expression. To understand what is OPath, lets say that this is like XPath but with objects in mind.
For instance, this query would get back all Person with a specific name:
Person[Name = 'Eric']
Eon is able to understand these queries and give back to you the corresponding objects. It's also able to evaluate an ordinal value given an expression and moreover sort any collection using an OPath query.
Here are is a sample application using Eon and the result.
First of all the object model we will work on:
Person p1 = new Person(); p1.Name = "p1"; p1.Age = 5; Person p2 = new Person(); p2.Name = "p2"; p2.Age = 10; Person p3 = new Person(); p3.Name = "p3"; p3.Age = 15; p1.Partners.Add(p2); p1.Partners.Add(p3); p2.Partners.Add(p3);
Then how to iterate throught all the partner's name of p1:
foreach(string name in nav.SelectElements("Partners.Name")) Console.WriteLine(name);
The result is "p2" and "p3".
Then how to evaluate the average age of all the partners of the p1 object:
Navigator nav = new Navigator(p1); Console.WriteLine(nav.Evaluate("avg(Partners.Age)"));
The result is 12.5 as p2 is 10 and p3 is 15.
We can also use complex queries like this one :
"Partners[(count(Partners) > 0) or (Name = 'p3')].Name"
Which also results in "p2" and "p3".
And finally, you can sort any collection like that:
values = new ArrayList(new object[] { p1, p2, p3 }); values.Sort(new NavigationComparer("avg(Partners.Age)")); foreach(Person p in values) Console.WriteLine("{0} {1}", p.Name, nav.Evaluate("avg(Partners.Age)", p));
The result is:
p3 p1 12.5 p2 15
(note that p3 has no value because it has no partner, so the average is "nothing")
And do you know the best news ? It is free. You can use it for what you want, commercial or not, useful things or not, ...
I provide a small documentation with the msi file here: EonSetup.msi. You can contact me if you have any question about EON. Keep connected, this is the first preview and I already have some known bugs.
Trackback address for this post
3 comments, 3 trackbacks
keep on this hard work, you're doing fine.
You are right, you can also use EON with o/r mapping tools like mine but also other ones. This can also be useful with ASP.Net data binding for making specific views on related objects without having to create proxy methods.
But to clear you comment, EON is not part of DTM, it's a completely separate library, even if they can work all together.
Comments are closed for this post.