0

I was looking at porting a small side project over to use Mongo, as it was getting more and more time consuming using Nhibernate for the current scenario.

I gave NoRM a try originally, and that had a branch which had support from cyclic references and worked fine, however I cannot find any documentation to indicate if the official c# driver supports it.

The situation and why I have a cyclic reference is because I have a location object, which contains a list of roads, each road has a link to another location. It is quite similar to a simple set of nodes in a pathfinder.

public class Location
{
    public int Id { get; set; }
    public string Name { get; set; }
    public IList<Road> Roads { get; set; }
}

public class Road
{
    public Location From { get; set; }
    public Location To { get; set; }
}

Now the problem is I have a whole world built up out of these objects (they have more properties in the real scenario) and they all interlink, however without being able to handle cyclic references I am not sure how I can solve this problem, as each road needs to know a start and an end point.

I know one compromise is to just get rid of the location object, and instead have an Id that references the location, but then I have to query each sub location individually. This is only done once and then kept in memory as there is a huge map that contains all possible locations and all possible routes so quick paths can be found between points.

It may be a case of the Location and Roads are not suitable for a document storage approach and can be stored another way...

Grofit
  • 17,693
  • 24
  • 96
  • 176

1 Answers1

1

The official C# driver doesn't really support "references" at all. The value of a field can be an ObjectID, but the concept of joins or references is not really implemented in the official C# driver.

Of course, even with "reference" support, these drivers would still be executing multiple queries.

It may be a case of the Location and Roads are not suitable for a document storage approach and can be stored another way...

Given the cases you've described, I would suggest looking at a graph database. There are several popular ones including Neo4J, Microsoft's Trinity, sones' GraphDB and a host of others.

Gates VP
  • 44,957
  • 11
  • 105
  • 108
  • Thanks for the info. Would it be executing the multiple drivers on the server though and just returning the aggregated results, or actually firing individual queries over? I thought it may be the former but dont have any factual evidence for that claim. The rest of the objects are not cyclic and seem to perfectly fit the document storage ideals, but as this one case of the initial map doesn't it may end up being a deal breaker, or as mentioned I just store this bit relationally and the other bits document based – Grofit Nov 14 '11 at 09:26
  • It would have to be client-side as there is no server-side "join" command. Do take a look at graph database, as I understand they support different underlying storage, so you may get all of what you need. – Gates VP Nov 14 '11 at 22:35