c# - WebApi receiving model with references (Not attached to Context) -
i trying pass complex type webapi having on apicontroller :
[httppost] public void dosomecrud(jobject data) { complexmodel item = data.toobject<complexmodel>(); // logic here }
my issue 1 of properties have inside complexmodel entity framework entity. don't have problems passing entity if detached, entity dbcontext model cannot passed webapi expected.
my question is.. : there anyway detach entity preserving references foreign keys ? because need references on webapi side.
thanks
it not best practice use model entity framework data transfer object (dto) web api because can problem serialization since models ef proxies supports lazy loading , navigation properties (if don't detach it).
the best practice is, separation of concern, should define own dto objects instead of using entity models directly ef.
simple example, if have customer
entity, should have customerdto
entity projects property customer
want.
Comments
Post a Comment