Skip to main content

Posts

Showing posts from June, 2016

MongoDB navigation property or making it behave as ORM in .Net

This is an implementation to make models to have  navigation properties work like ORM does for us.

What actually happens in ORM to make navigation properties work? Entity Framework has proxy classes implementation to allow lazy loading and eager loading implementation. While creating proxy classes it also changes definitions for actual classes to make navigation properties work to get values based on Model's for navigation properties. Most of ORMs work in same fashion like Telerik DataAccess has enhancer tool which changes class definition at compile time to enable navigation properties.

In this implementation, we would retain the original class but we would have extension methods to allow initializing properties to have navigation proprieties work.

Let's first create desire model on which we need to implement. I am picking up simple one-to-many relationship example from Person to Address.

public class Person { public int PersonId { get; set; } public string Name …