Copied to clipboard

Flag this post as spam?

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


  • stevo 63 posts 106 karma points
    Jun 16, 2015 @ 01:05
    stevo
    0

    PetaPoco One To Many with more than 4 POCO's

    Hi, I'm working on a new Umbraco project with a external database and I love it. But I've run into a problem and question now I have a query with more then 4 joins now.

    Before I worked with the following line (and it works great!)

    db.Query<Entity1, Entity2, Entity3, Entity4, Entity1>(new Relator().MapIt, sql).SingleOrDefault();
    

    But now I have to join more tables.

    I found the following method

    public IEnumerable<TRet> Query<TRet>(Type[] types, object cb, string sql, params object[] args)
    

    But I can't get it to work! I don't know how to pass the relator callback into the method.

    Our help would be greatly appreciated, Thanks Stefan

  • Phill 115 posts 289 karma points
    Aug 26, 2016 @ 15:33
    Phill
    0

    Hi Stevo, This was posted a while ago but did you ever find a solution? I'm encountering the exact same problem. Need to use a Realator with more than the standard 4 joins (just 1 more, not asking for much ;) ).

    Would love to hear what you came up with for a solution.

    Cheers, Phill

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 26, 2016 @ 18:26
    Dan Diplo
    0

    Go modify the source? :)

    https://github.com/umbraco/Umbraco-CMS/blob/10422079b6aa1cc2690bed9dd136cdaaadaef007/src/Umbraco.Core/Persistence/PetaPoco.cs

    But can't you just pass in an SQL query as a string, with as many joins as you need, so long as it maps to your return model?

  • Phill 115 posts 289 karma points
    Aug 26, 2016 @ 18:46
    Phill
    0

    Hi Dan, thanks for the response. I'm trying to avoid modifying the source if possible just to keep the project easier to update and maintain.

    I'm retrieving a list of objects that have have List

    Am I missing something?

    Sample of my code (generic), just want to be able to add SubObj5.

    
    public IEnumerable

    How you would do the above with just a query string? If it was a single model and that model made up of single models I get it, but when you have to use a Relator to iterate and map to a list of sub models, how would that work?

    Thanks again.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Aug 26, 2016 @ 19:14
    Dan Diplo
    0

    I guess I was being a bit flippant saying modify the source, but originally peta poco was meant to be a simple class that could be modified. So you could take the entire class, move it to your own project, and modify it that way without touching the Umbraco core. Though it's probably not that simple anymore. Guess some kind of extension method wouldn't work?

    I can see now what you are trying to do and you are right, there isn't a simple way - I was thinking you just wanted to perform multiple joins that mapped to a single object.

  • Phill 115 posts 289 karma points
    Aug 26, 2016 @ 20:07
    Phill
    0

    Hi Dan, I think where my knowledge comes up short is at the "extension method" part and how to implement that. I'd love to be able to extend Umbrabo.Core.Persistence where the PetaPoco code lives so that I can easily keep my Umbraco core up to date and not have to worry about merging source every time.

    If you have any suggestions to point me in the right direction there would be greatly appreciated.

    Cheers, Phill

  • Caglar Tasci 19 posts 125 karma points
    Jun 16, 2017 @ 09:13
    Caglar Tasci
    0

    Sitting here and having the same problem. Unfortunately i could not find any solutions too. i found a suggestion here but could not turn it into usable code. Hope that some experienced community member can help us. i dont really want to modifying the source code but changing it by copying would be a possibility

    i already tried some nested joins to create a result table to merge multiple tables as one result but without any success.

    ps: default" joins and automapping with petapoco works without any issues

Please Sign in or register to post replies

Write your reply to:

Draft