Metadata-driven Community queries
First step was to make my Community site sync entity attributes automatically which is described here.
When I added support for searching and other stuff in my site which requires a lot of queries, I noticed that I do not have metadata driven support for queries.
So currently I need to write something like this to query something:
Next step was to make use that strongly-typed approach here as well.
For this we need to extend FrameworkEntityQueryBase class to add support for “converting” it to our known metadata class.
So we need to add new method named AsMetadataQuery as following:
It returns back MetadataFrameworkEntityQuery class that has generic type parameter of entity attribute definition class.
Class itself is pretty simple:
It just overwrites indexer to provide Expression for pointing to some of the attribute name. It uses helper method to find MemberAccess expression body within the expression.
After implementing this now we are able to write something like this:
It would be nice also to have support for other members for the type you get back from AsMetadataQuery() method. Currently this is not supported and back you get only class that provides metadata-driven indexer. Will see what we can do for the next version.
As usual – package could be found in nuget.episerver.com. Name for the package – “Geta.Community.EntityAttributeBuilder”.
Hope this helps!