Handling entity inheritance

144 views
Skip to first unread message

Federico Lois

unread,
Apr 25, 2011, 7:25:07 PM4/25/11
to ravendb
Newbie question ahead. :)

Lets say that I have:

public class A
{
public string Id { get; set; }
}

public class B : A
{}

public class C : B
{}

AFAIK each one of those will be stored as a\1, a\2, b\1, b\2 ... and
so on. That requires me to do the query over each type to query over
all the entities or to create a polymorphic index (that I couldn't
understand the underlying mechanism it uses yet to apply it to my
model).

On the other is it possible to just store all of them under the
mynewidentifier\1, mynewidentified\2, ... and so on? Would it step
into any particular design pitfall? Is there any facility for that? As
it makes sense in my particular case for them to be stored under the
same room type.

The reason why I am asking is because I already have a model with such
dependencies and would love to be able to keep it unchanged.

Thanks in advance,
Federico

Frank Schwieterman

unread,
Apr 25, 2011, 7:42:14 PM4/25/11
to rav...@googlegroups.com
I haven't tried it myself, but it looks like you could use:
http://ravendb.net/faq/indexing-across-entities

Ayende Rahien

unread,
Apr 26, 2011, 3:36:31 AM4/26/11
to rav...@googlegroups.com
It is very hard to answer such questions in isolations, what is exactly your model?

Chris Marisic

unread,
Apr 26, 2011, 9:17:00 AM4/26/11
to rav...@googlegroups.com
It sounds like he just needs direction on creating ANY polymorphic index.

Federico Lois

unread,
Apr 27, 2011, 1:00:39 PM4/27/11
to ravendb
The model is quite simple. It looks like this:

public class Post
{}

public class Blog : Post
{}

public class Notification : Post
{}

.....

Post only have the information required to address the basic
characteristics.

Each new application/plugin creates its own new type (something I
cannot know in advance). What I need is to be able to handle all of
them as if they were all Post types, and when rehydrating them create
the appropriate object. All objects are being discoverable through
MEF.

The same would work with interface thoughs. Is that something that can
be done?

Regards,
Federico

On 26 abr, 04:36, Ayende Rahien <aye...@ayende.com> wrote:
> It is very hard to answer such questions in isolations, what is exactly your
> model?
>
> On Tue, Apr 26, 2011 at 2:25 AM, Federico Lois <federico.l...@gmail.com>wrote:
>
>
>
> > Newbie question ahead. :)
>
> > Lets say that I have:
>
> > public class A
> > {
> >     public string Id { get; set; }
> > }
>
> > public class B : A
> > {}
>
> > public class C : B
> > {}
>
> > AFAIK each one of those will be stored as a\1, a\2, b\1, b\2 ... and
> > so on. That requires me to do the query over each type to query over
> > all the entities or to create a polymorphic index (that I couldn't
> > understand the underlying mechanism it uses yet to apply it to my
> > model).
>
> > On the other is it possible to just store all of them under the
> > mynewidentifier\1, mynewidentified\2, ... and so on? Would it step
> > into any particular design pitfall? Is there any facility for that? As
> > it makes sense in my particular case for them to be stored under the
> > same room type.
>
> > The reason why I am asking is because I already have a model with such
> > dependencies and would love to be able to keep it unchanged.
>
> > Thanks in advance,
> > Federico- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Ayende Rahien

unread,
Apr 28, 2011, 2:30:44 AM4/28/11
to rav...@googlegroups.com
You probably better off modifying the entity tag for the all the entities inheriting from Post to be Posts
That would allow you easy querying across everything.
Reply all
Reply to author
Forward
0 new messages