Skip to content

Add "Navigational Properties" support like EF #12

@Turnerj

Description

@Turnerj

Changes tracked in: https://github.com/TurnerSoftware/MongoFramework/tree/ef-navigation-properties

While a document-based database can store nested data, you may not want to store all objects in a nested fashion. You can add foreign keys on entities and manually query them currently however it can be useful to be able to access the related entity through a navigational property.

In Entity Framework, this is achieved through the use of virtual properties where it instantiates a proxy that can do the required lookup. It supports both eager loading (specifically defining which objects you want data for) and lazy loading.

While it isn't a good idea to shoehorn every relational database feature from EF into MongoFramework, there is some utility in some of the functionality.

It shouldn't be very difficult to support a 1..n relationship through virtual properties like virtual ICollection<Post> Posts { get; set; }. Currently I'm not sure how to implement a 1..1 relationship through the same method as EF does some magic behind the scenes.

Right now, it doesn't seem to make sense to support eager loading as I can't see it improving performance.

At minimum I see the following things needed:

  • Custom Linq processor that instantiates the proxy class (eg. ICollection<Post>)
  • Updates to valid mappings, need to prevent virtual properties from being considered part of the BSON mapping
  • New mapping processor to pick up new attributes part of the DataAnnotations namespace
  • Potential updates to change tracking (virtual properties shouldn't count as changes - this might be accomplished with mapping updates)

This is a nice feature to add but will need to be careful to make sure it generally works the same way as EF. If it has minor differences, that's fine. If it has major differences, it might be worth re-considering this functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementEnhancements & features

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions