Single-page application, upshot.js, DbContext and DbDataController: only entity models supported?

When using examples for a single page application, I have the following TodoItem controller:

public partial class MVC4TestController : DbDataController<MVC4TestContext> { public IQueryable<TodoItem> GetTodoItems() { return DbContext.TodoItems.OrderBy(t => t.TodoItemId); } } 


Question 1:
It seems that only EntityModels are supported?
When using a real ViewModel (a model used only for views, not used as a 1: 1 mapping for a database object), DbDataController does not support this.

Also using Linq.Translations or PropertyTranslator does not work, see this code snippet

 private static readonly CompiledExpressionMap<TodoItem, string> fullExpression = DefaultTranslationOf<TodoItem>.Property(t => t.Full).Is(t => t.Title + "_" + t.IsDone); public string Full { get { return fullExpression.Evaluate(this); } } 


Question 2:
What is the recommended design when using SPA, DBContext and ViewModels?

+7
source share
1 answer

As far as I know, it is based on the use of "real" classes of models related to DbContext. I have the same problem as you - I need to use my own DTO objects that are β€œflat”. Serialization Json currently cannot serialize data that has parent references in child objects (circular references). I usually don’t need a tree of objects, so I created smaller classes that are perfect for presentation. I tried using a regular controller with JsonResult and parsed the returned model in ko.mapping.fromJS after receiving the data. This works fine. But - you need to take care of all the nice things that MVC4 models you are working with are already associated with (for example, creating navigation, etc.). Perhaps someone finds a workaround to "fake" DbContext with DTO data.

+3
source

All Articles