[odb-users] Re: odb-users Digest, Vol 63, Issue 7

Andrew Cunningham odb at a-cunningham.com
Tue Nov 17 12:28:36 EST 2015


Hi Sverre,
The brilliance of ODB is you just code your relationships using C++ and
familiar STL collections and you are 'done'.



#pragma db object pointer(std::shared)
class D
{
...
}

#pragma db object pointer(std::shared)
class C
{
...
std:: list< std::shared_ptr<D> > dlist_;
}

#pragma db object pointer(std::shared)
class B
{
...
std:: list< std::shared_ptr<C> > clist_;
}
#pragma db object pointer(std::shared)
class A
{
....
std::shared_ptr<B> b_
}

When you load your object ( or list of objects A's)  from the database, the
complete hierarchy is loaded.



> Hi,
>
> I am currently playing “getting to know ODB”, and I think I’ve worked out
> how to do most of what I want to do.
>
> There is one thing I can’t really work out - what is the most efficient
> way to load into memory a object hierachy, where some objects have a
> one-to-many relationship to other objects.
>
>
> So if I have tables A, B, C and D, where
>
>  - A have a one-to-one relationship to B
>  - B have a one-to-many relationship to C
>  - C have a one-to-many relationship to D
>
> Example instance graph:
>
> A - B + C1
>       + C2
>       + C3 + D1
>            + D2
>
>
> I would now like to load a number of A’s (say, about 200) with full object
> graph as well. How can this be done most efficiently ? I can’t see a way
> using object views, as they do not allow the objects they load to have
> collections in them.
>
> I don’t exactly need actual code for this, more a general descriptoin of
> the best way to achieve loading of a complete hierachy. Lazy loading won’t
> do, as I need to serialize the whole bazinga and ship it over a wire to a
> client app.
>
>
> (BTW, the background is that in order to test out ODB, I’m reconstructing
> in C++ a solution I’ve done for a customer in C#, where I have used the
> Entity Framework as ORM and WPF frontend. I’m redoing in C++ using ODB and
> QT. )
>
>


More information about the odb-users mailing list