[NoRM MongoDB] Circular references and more

401 views
Skip to first unread message

Jørn Wildt

unread,
May 23, 2010, 9:52:19 AM5/23/10
to NoRM MongoDB Group
For anyone interested: I have added support for circular object references
inside a single document. Now you can store a complete tree with parent
references (making it circular) in one document:

Tree top = new Tree() { Title = "Top" };
Tree child = new Tree() { Title = "Child", Parent = top };
top.Children.Add(child);

It only works for CLR objects, not arrays nor expando objects or
dictionaries.

I have also added a "ignore" configuration, such that your POCO domain
objects do not have to know anything of NoRM:

MongoConfiguration.Initialize(r => r.For<User>(u => u.ForProperty(user
=> user.FirstName).Ignore()));

At last there is also support for BSON "type convertes". Such converters can
be registered at startup and are used to convert otherwise non-serializable
CLR values into serializable BSON friendly values. For instance a
CultureInfo converter that converts a CultureInfo into a string like "en-US"
and back again:

public class CultureInfoTypeConverter : IBsonTypeConverter
{
#region IBsonTypeConverter Members

public Type SerializedType
{
get { return typeof(string); }
}

public object ConvertToBson(object data)
{
return ((CultureInfo)data).Name;
}

public object ConvertFromBson(object data)
{
return new CultureInfo((string)data);
}

#endregion
}

All of this can be found here: http://github.com/JornWildt/NoRM

Kind regards, Jørn Wildt

--
You received this message because you are subscribed to the Google Groups "NoRM mongodb" group.
To post to this group, send email to norm-m...@googlegroups.com.
To unsubscribe from this group, send email to norm-mongodb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/norm-mongodb?hl=en.

Henning

unread,
May 23, 2010, 11:50:41 AM5/23/10
to NoRM mongodb
Sounds really nice. Hopefully Andrew can merge it into his repo :)

Andrew Theken

unread,
May 23, 2010, 1:15:51 PM5/23/10
to Henning, NoRM mongodb
I need to review it and make sure we have some good test for it, but it's a neat concept.

I do worry that we're putting a great deal of extra onus on the Serializer and to some degree straying from the concept of "document-oriented," but then again, you don't have to use the functionality.

//Andrew Theken

Henning

unread,
May 23, 2010, 1:56:41 PM5/23/10
to NoRM mongodb
Andew,

You do have a point. Maybe some stuff just don't belong in the driver,
but perhaps in a contrib project or something. A driver should just
provide the basic functionality, but then what is basic functionality
in a driver.
> > norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsubscribe@google­groups.com>
> > .
> > > For more options, visit this group athttp://
> > groups.google.com/group/norm-mongodb?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "NoRM mongodb" group.
> > To post to this group, send email to norm-m...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsubscribe@google­groups.com>
> > .

Jørn Wildt

unread,
May 23, 2010, 3:32:22 PM5/23/10
to Andrew Theken, Henning, NoRM mongodb
> I do worry that we're putting a great deal of extra onus on the Serializer
and to some degree straying from the concept of "document-oriented,

I think that follows automatically once you go down the road of strongly
typed access to a document database. The moment you decide that serializing
.NET types is good (which I believe it is!) you also get lots of new
challenges. Supporting strongly typed database access is quite different
from using JSON notation in it's basic form. Circular (and shared)
references is just one of the differences.

It also makes a difference when you go from "just supporting serializing" to
an "enterprise ready" driver. Plugins like type converters is one of the
differences. Take NHibernate for instance - it can store any POCO, but you
need lots of configuration points in order to support all the weird things
people wants to do with your great software.

> I need to review it and make sure we have some good test for it

There are a few tests already. I think it is more less impossible to cover
all the weird combinations of objects, dictionaries, lists and expandoes,
but let me know if you have some specific case you want me to cover.

/Jørn
> norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsu...@googlegroups.com>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/norm-mongodb?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "NoRM mongodb" group.
> To post to this group, send email to norm-m...@googlegroups.com.
> To unsubscribe from this group, send email to
> norm-mongodb...@googlegroups.com<norm-mongodb%2Bunsu...@googlegroups.com>
> .
Reply all
Reply to author
Forward
0 new messages