This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Has anyone successfully been able to Post & Put entities via a ApiController directly without resorting to DTO's? I am struggling to get them working. Take this simple Post method code:
Person comes in with a entity state of Default and not New so the add moans about it. Also although I have provided my own GeneratedId() and it gets called when the entity comes into the call, it gets reset to blank. It's late here in the UK and it is obviously something really simple but do you have a full ApiController example showing Post, Put and Delete? Thanks, Jim |
|
|
Use UnitOfWork.Attach with the overload that allows you to specify an AttachMode and use AttachMode.Import, this will resolve if the entity already exists and update the EntityState accordingly. e.g.
|
|
|
Hi Jeremy, I should have updated the post to say that I had worked that out earlier today but thanks for the update. What about Put when you have a signature like this:
The route will be core/consumers/{id}?{version} With the consumer without the Id / LockVersion assigned as I want them to come in via the Uri. Question is that I haven't had time to investigate is how I select the entity by the passed id but update the properties from the passed in consumer entity. I have for now reverted back to DTO's with an altered DataContract.vm template to take into account some alterations I require for the way I am surfacing the data items out of the API. Thanks, Jim |
|
|
Im not sure if the Id value would be bound both to the string argument on the method as well as unbound to the entity/DTO, but assuming it is then you could use UnitOfWork.Import(consumer) which will handle the fetch and update or create new entity for you. Otherwise you would be best to not have Consumer as part of the method signature and then fetch back the existing instance via a FindById and then call UpdateModel on that retrieved instance to perform the update via unbinding.
|
|