Wednesday 15 July 2015

c# - Web API and OData for change tracking? -



c# - Web API and OData for change tracking? -

i'm using web api 2 controllers, dto's (using automapper) , separate service layer. dal implements uow , generic repository patterns ef6. typical controller looks this:

public class customertypecontroller : entitycontroller<dto.customertype> { private readonly icustomertypeservice customertypeservice; public customertypecontroller(icustomertypeservice customertypeservice) { this.customertypeservice = customertypeservice; } public override ihttpactionresult get(int id) { var item = mapper.map<dto.customertype>(customertypeservice.get(id)); homecoming ok<dto.customertype>(item); } public override ihttpactionresult create(dto.customertype customertype) { homecoming save(customertype); } public override ihttpactionresult update(dto.customertype customertype) { homecoming save(customertype); } private ihttpactionresult save(dto.customertype customertype) { var customertypemodel = mapper.map<dto.customertype>(customertypeservice.save(mapper.map<model.customertype>(customertype))); homecoming ok<dto.customertype>(customertype); } public override ihttpactionresult delete(int id) { customertypeservice.delete(id); } }

this controller simple entity. have entities much more complex number of nested navigation levels.

using current solution, cannot leverage ef's alter tracking because of restful nature of webapi. so, when save updates db, ef generates update query fields. not want because:

only changed columns should sent db my entity auditing doesn't grab changed columns , values.

so i'm using ef6 model designer (i utilize database first) , reading tables. , looks overkill @ moment.

so solve alter tracking problem, need utilize packages such changetracking or trackableentities. avoid these don#t want add together additional references on client-side or incur bigger payloads.

alternatively, utilize odata's delta webapi, although i've read doesn't play json. moreover, utilize jil , protobuf media formatters too.

the lastly solution utilize odata controllers completely. maintain same construction controls shown above. i'm not interested in odata's paging, filter, sorting, etc.

at stage might decide utilize odata if solves alter tracking problem.

is way go or there alternatives or workarounds?

c# asp.net-web-api odata

No comments:

Post a Comment