0

Asp.net MVC + EF: When I try to send back to client from controller, a collection that I retrieve from EF, I get an error on client. debug shows that the details are not sent appropriately. it does work fine when I copy the data into any other DTOs that I created and send them instead. just init another object and send it works. why ???

thanks !!!

moshi
  • 280
  • 4
  • 16
  • It's usually because you have lazy loading enabled and the serializer tries to read a collection, whish should be lazy loaded, when the context no longer exists. – JotaBe Jun 06 '14 at 00:08

1 Answers1

0

so this is how it should work. reason: poco ef objects can't be serialize properly because of relationships conventions, and we use dto instead to return only required properties.

WebApi Controller returned value in Entity Framework 5 and MVC 4 project

hope it helps

Community
  • 1
  • 1
aamir sajjad
  • 3,019
  • 1
  • 27
  • 26