October 2, 2014

Data, Model, ViewModel, Knockout ViewModel... WAAH!

I just finished the pluralsight class "Parent-Child Data with EF, MVC, Knockout, Ajax, and Validation". While it's a good class and the author has some great insights on how to cleanly implement a web application that uses knockout on the client, I was struck by how many hoops we jump through here to get data from database to client and how many times we convert the data along the way:

  1. Get data from SQL Server.
  2. Entity Framework (or another ORM) maps the data to an entity data model.
  3. Convert the entity data model to a view model.
  4. Convert view model to a JSON object that knockout can use.

Or, in terms of how we represent the data:

  1. Row in SQL Server
  2. C# Object (Entity Framework)
  3. C# Object (POCO)
  4. JSON object

...and we do the reverse when the user posts data to our controller. This just seems crazy. We're converting back and forth without good reason. The result is methods like "CreateSalesOrderViewModelFromSalesOrder".

Meteor does have its downsides, but the principles "One Language" and "Database Everywhere" are a step in the right direction.

Comments powered by Disqus