Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • firepol 125 posts 173 karma points
    Oct 17, 2013 @ 17:01

    LinqToUmbraco alternatives?

    Hi there,

    when I begun using umbraco, there was still a feature to generate .net classes from the Document Typed. This feature has been dropped na long time ago...

    Now there is LinqToUmbraco Revisited.

    Anyway, that helps to get only published nodes. To get also the unpublished ones I found a Document DataProvider in these LINQ To Umbraco Extensions.

    LINQ to Umbraco Extensions has no update since 2012 and since I upgraded from 4.x to 6.x the website is going damn slowly when I use a snippet like this:

    using (var ctx = new DocumentDataProvider())
        Event newEvent = (from r in ctx.LoadTree()
                  where r.Id == nodeID
                  select r).FirstOrDefault();

    I think I have to rewrite all my backend components... (in this example I have a document type called "Event").

    I'd like any suggestions from anybody that encountered similar problems.

    Is there, maybe, in the new umbraco 7 support for .net classes? I mean document types to .net class... would be nice...

    Thanks for letting me know...

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 17, 2013 @ 17:27
    Ismail Mayat


    Checkout this excellent blog post on the current state of umbraco code first **



  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Oct 17, 2013 @ 18:19
    Jeroen Breuer

    This documentation shows the best way to currently do strongly typed queries:


  • firepol 125 posts 173 karma points
    Oct 18, 2013 @ 09:19

    @Ismail: I will have a look at the article, thanks. Didn't know that umbraco offers a "code first" alternative. Would be handy in my case, but this is for the future or do we have a solution now, for websites using already document types created in the UI? (convert and use them like with linq2umbraco, but beinbg able to access also the unpublished ones)

    @Jeroen, by strongly typed you mean getting as result IEnumerable<IPublishedContent> or IPublishedContent?

    Not really useful in my case.... what I meant with .net classes is to get back the node (or in my case the unpublished node, so the document) as object/POCO class (with properties taken automatically from the Document Type) just as linq2umbraco.

    Linq2umbraco takes all your document types and generates c# poco classes and a datacontext I can query with LINQ. But it works only with published nodes.

    I need access to unpublished nodes.

    I found also uQuery and support for Document. But this doesn't help either, as it's not powerful enough for my needs (thus I need LINQ).

    Seems that for now, even if slow*, the only solution I have is to keep using DocumentDataProvider. In my case, this is very slow. To get all documents of a specific type, and count, them, like this:

    int countEvents = (from r in ctx.LoadTree<Event>() select r).Count();

    it takes 20 seconds in my website (823 documents of type "Event"). My website has a total of 15'600 documents -I did a DB query for this- (SELECT COUNT(*) FROM cmsDocument).

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 18, 2013 @ 13:12
    Ismail Mayat


    At some point in v7 codefirst will become first class citizen with pocos being generated for you. For the time being there are another set of options:

    1. Usitebuilder - not to keen on performance - generate pocos by hand or use
    2. uMapper - part of ucomponents, you have to create the pocos yourself
    3. - i have used this it will generate the pocos for you however i am hydrating using uquery e.g.

              //get the final summary results nodes they live under 1089 which is called results text
          var resultNodes = uQuery.GetNodesByType("Result").Where(n=>n.Parent.Id==1089); 
      //hydate the result model basically we are going from node to strongly typed object which is easier to work with
      List&lt;Result&gt; results= resultNodes.Select(ModelFactory.CreateModel&lt;Result&gt;).ToList();

    I think for you option 3 would be best and it will meet your criteria for websites using already document types created in the UI. Although for usitebuilder there is a package to export out pocos



  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 18, 2013 @ 15:44
    Ismail Mayat


    Here is a crazy idea. Setup and install Umbraco.CodeGen. Next setup a GatheringNodeData event on the internal index and during the indexing process using INode hydrate the poco. Then serialise the poco to json (use .net serialiser or newtonsoft json) then inject the json string into the index.

    Now when you want to get the strongly typed object for a given node just pull it out the index and deserialise the json string to poco. So this would run alot faster than hydrating using INode which is how CodeGen works. Like I say its just a crazy idea.



  • firepol 125 posts 173 karma points
    Oct 22, 2013 @ 13:13

    Dear Ismail,

    THANK YOU for the article, I read it and it opened a new era in my future umbraco projects!

    But for now, to maintain an old project already using linq2umbraco + the extension data provider I mentioned, I have to find a practical way to speed up things.

    I deleted from the DB many versions I didn't need anymore (e.g. 12'000 documents, only 2'800 set as "newest = 1") but that didn't do any performance change.

    I noticed, anyway, that deleting 700 of the 800 active documents of type "Event", the Loadtree is fast again.

    This is not optimal, but since the old events are old... and the customer wanted just to keep them for "overview" (and statistic) purposes, for my specific case I find easier to save everything to an excel file and then delete all the old events from the past. Like this the customer is happy to have the old stuff in a searchable file (Excel is kinda good for this) and umbraco is fast again.

    About your crazy setup, the idea seems nice but I guess it's better to wait for some stable and supported solutions, I don't want to end up like with linq2umbraco, adopting a solution that nobody will support and I'll need to maintain myself. So I guess I'll wait for umbraco 7 and see what the development teams recommends to use... or use an official and well maintained package. uSync and CodeGen have my attention. uSiteBuilder if I've well understood will not be supported anymore soon.


  • Aaron Powell 1708 posts 3046 karma points c-trib
    Oct 23, 2013 @ 00:30
    Aaron Powell

    Don't use LINQ to Umbraco, seriously, just don't. It's not maintained and it doesn't scale.

    Don't bother with those extensions I wrote either, unless you plan on maintaining the code yourself, it's over 3 years since I last looked at that code, heck I'd forgotten it even existed, so what's there is there and it's all that'll ever be there.

    I'm not holding my breath on code-first being in-the-box of Umbraco, mostly because there's a lot of different opinions around how it should work (in the community) and it's a really complex problem to try an solve.

    uSync and CodeGen are an interesting approach but I don't like that XML is the authoring language or that you end up with two generated files. I'm presently collaborating on a pure C# code-first approach which I intend to integrate with RenderModel so it can be used in Views.

Please Sign in or register to post replies

Write your reply to: