Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port From Entity Framework to MongoDB

I'm planing to port from entity framework 4.0 to MongoDb. What are the best practices that can minimize the impact since the project is having social networking functionality hence, maintain a complex relational database.As a result, performance should be a matter if we use relational database.

We have used domain Layer(using POCO), repository pattern and DTO Mapping in the project.Also, What are the advantages and disadvantages of the decision ? At the same time, how it affect to my domain layer implementation ?

like image 675
marvelTracker Avatar asked Nov 04 '22 13:11

marvelTracker


1 Answers

If you want to 'minimize impact' you'll want to create a database in MongoDB the one you have in SQL. Since there are no joins in the database you'll need to do multiple reads to complete your query. In itself that's not too bad because MongoDB is really fast, but obviously it has other issues (concurrency, etc.).

If, however, you want to move over fully to the NOSQL-way of doing things you'll likely not be able to 'minimize impact', you'll need to make substantial changes to the way you store content, the way you access it and the way you update it.

Storage: You'll likely create documents in your database that are denormalized and much closer to 'ViewModels' than 'Models'. You might for example store a count of child records in a parent record so that you can display it without having to load them or count them.

Access: You might end up using Map-Reduce for some queries to your database which is a very different mind-set from a traditional query.

Updates: In all likelihood your approach to updating will be different in order to take advantage of the many fine-grained MongoDB update features like $inc. Instead of posting back some large view model and then applying it to your model and then updating the database you might instead provide a much finer-grained Ajax call back that updates a single value. Take a look at CQRS for more ideas on how to think about models for updates vs queries.

like image 161
Ian Mercer Avatar answered Nov 09 '22 13:11

Ian Mercer