Search code examples
asp.netasp.net-mvcentity-framework-4.1singlepageasp.net-spa

ASP.NET SPA with a legacy domain objects


Looking at the Single page application beta in the MVC 4 I don't see how I can use my legacy domain objects as the model. It seems to require that the model use the entity framework to using DbDataController to get the data etc.

I do not understand the entity framework so I am probably missing something.

How can I use my legacy domain (with it's own DAL) in the SPA of MVC 4?


Solution

  • This was answered by somebody else in an ASP.NET forum.

    You won't be able to use anything other than EF if you want to use some of these RAD tools. However, SPA builds on top of MVC, so you should be able to build your own version rather easily. The important components would be building a DataController on top of ApiController and a js consumer for the service provided by your DataController. It's possible that if you were to format your models in the same format as the EF output (I think it's just OData) you could use upshot.js, as well and only have to implement a DataController to format your domain models.

    I will add the following after working with it for a couple of days that you could, theoretically, use it if the following are handled/fixed by you and future versions of the SPA.

    You can create a controller that inherits from System.Web.Http.Data.DataController (and maybe even ApiController). The objects it returns then must just have a property decorated with the System.ComponentModel.DataAnnotations.Key() attribute. I can get the views to work fine but some of the more advance features, like grouping, I am having problems with.

    Readonly property will not be returned I guess because of a problem with the current JSON serializer used. Should be fixed.

    Of course the entire object will be serialized which can be very problematic if your domain objects are complex with child objects. Especially if some of those objects have serialization issues of their own.

    Related to the complex serialization the current JSON serializer cannot handle circular references in the domain objects referenced.

    I have also run into problems getting update/deletes/inserts being posted back when using my own Controller that inherits from System.Web.Http.Data.DataController (the examples use DBDataController).