Hi, does anybody knows if it is possible to query the umbraco database with a select? I have a custom document type named "Product" and i'd like to query the db in order to select only products with colour=red or with quantity > 100. Is it possible? I don't use xslt just razor macro or user control macro with umbraco 4.11. So far I accomplish that by using uQuery.GetDocument(9999).GetChildDocuments() and then filter the list with a foreach but that loads all product in-memory.
Sure this is possible as lang as you know the database and table architecture. But I wouln't recommend this. A better way would be a LINQ query, but I don't know how those are mapped in behind against the database. Does anyone ones more about the LINQ possibilities against the umbraco backend?
@Andreas - since the published nodes are using the XML cache, they are fast. Documents on the other hand, can follow the same LINQ syntax, but they will hit the database a good few times! :-(
Query Umbraco DataBase
Hi, does anybody knows if it is possible to query the umbraco database with a select? I have a custom document type named "Product" and i'd like to query the db in order to select only products with colour=red or with quantity > 100. Is it possible? I don't use xslt just razor macro or user control macro with umbraco 4.11. So far I accomplish that by using uQuery.GetDocument(9999).GetChildDocuments() and then filter the list with a foreach but that loads all product in-memory.
Thank you
Gian Paolo
Sure this is possible as lang as you know the database and table architecture. But I wouln't recommend this. A better way would be a LINQ query, but I don't know how those are mapped in behind against the database. Does anyone ones more about the LINQ possibilities against the umbraco backend?
Hi Gian,
Assuming that your content is published, you could use `uQuery.GetNodesByXPath`?
Then once you have the nodes, you can get the Document from the Id.
Cheers, Lee.
If XPath isn't your thing... you could use LINQ syntax:
Cheers, Lee.
Thanks lee for pointing the LINQ way out.
@Andreas - since the published nodes are using the XML cache, they are fast. Documents on the other hand, can follow the same LINQ syntax, but they will hit the database a good few times! :-(
Cheers, Lee.
Lee, as fast as ever !
FYI, the XPath way would be more efficient, as only the nodes in the result set will be constructed (+ it gets compiled and cached).
I've decided for and xpath solution since there will be a lot of products . Thank you all very much!
Gian Paolo
Hi Gian, great, happy to help.
(Don't forgot to mark the post as a solution)
Thanks, Lee.
is working on a reply...