2

The Entity Framework uses proxy classes for some of its internal stuff, as seen in this question we have to disable it, because it cause issues with the serialization of the objects.

My question is what will be the consequences if I disable the ProxyCreation globally in my project (to avoid serialization issues) ...???

zsubzwary
  • 1,196
  • 1
  • 14
  • 22

1 Answers1

1

They are mainly around enabling lazy loading, but can provide some performance improvement for persisting changes, though honestly I'd say this is highly situational to present anything that is noticeable.

I would be cautious about the need to serialize entities. For instance if it is to return entities from a controller/API I would recommend defining POCO view models or DTOs that reflect the data needed by the consumer for this purpose rather than serializing the entities. The key reasons for this is that serializing entities can expose more information about your data than the consumer needs, which also means more data sent across the wire than was needed. It also can represent a misleading representation of the data in the sense that collections/references that are not eager loaded will be #null, so does that later mean that they have no data, or that it simply wasn't loaded?

Autofac supports .ProjectTo<T> which integrates into EF's IQueryable operations to simplify mapping to view models vs. using .Select.

Steve Py
  • 26,149
  • 3
  • 25
  • 43