I am trying to use DbDataController to query and update my database.
Querying works fine, but it seems the way I am trying to use the Update framework is not working. (I should mention that I am using a rather current build of the Web API from the Git repository).
The main reason it seems is that the DbDataController and DataController classes assume that the the parameters passed to any of the Insert/Update/Delete methods are actual model entities.
However, in my case they are not, they are small projections (DTOs) which I then map inside the Web API methods to actual model entities. These actual entities cannot be added to the ChangeSet anymore, as the ChangeSet is created right when the controller
action is called, the changeset entries are the parameters passed to the action (the internal classes SubmitActionDescriptor and SubmitActionProxyDescriptor seem to handle that). So, when I call DbDataController.UpdateEntity, it throws an exception because
it cannot find the mapped entity in the ChangeSet, as it is not one of the action parameters.
It seems there is not proper way with DbDataController or DataController to handle this situation?
I do not want to expose the full model classes to the client, that is why I am using these smaller and more efficient DTOs.
kwaclaw
Member
3 Points
6 Posts
How to deal with DTOs that are not model entities
Jun 22, 2012 11:52 PM|LINK
I am trying to use DbDataController to query and update my database.
Querying works fine, but it seems the way I am trying to use the Update framework is not working. (I should mention that I am using a rather current build of the Web API from the Git repository).
The main reason it seems is that the DbDataController and DataController classes assume that the the parameters passed to any of the Insert/Update/Delete methods are actual model entities.
However, in my case they are not, they are small projections (DTOs) which I then map inside the Web API methods to actual model entities. These actual entities cannot be added to the ChangeSet anymore, as the ChangeSet is created right when the controller action is called, the changeset entries are the parameters passed to the action (the internal classes SubmitActionDescriptor and SubmitActionProxyDescriptor seem to handle that). So, when I call DbDataController.UpdateEntity, it throws an exception because it cannot find the mapped entity in the ChangeSet, as it is not one of the action parameters.
It seems there is not proper way with DbDataController or DataController to handle this situation?
I do not want to expose the full model classes to the client, that is why I am using these smaller and more efficient DTOs.
Maybe I am overlooking the obvious approach?
Grateful for any pointers!
Karl