What would be the consequences if I disable the ProxyCreation globally in Entity Framework?

自闭症网瘾萝莉.ら 提交于 2020-01-24 14:14:25

问题


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) ...???


回答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.



来源:https://stackoverflow.com/questions/55769808/what-would-be-the-consequences-if-i-disable-the-proxycreation-globally-in-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!