• EF6 Working with Proxies ProxyCreationEnabled


    When creating instances of POCO entity types, the Entity Framework often creates instances of a dynamically generated derived type that acts as a proxy for the entity. This proxy overrides some virtual properties of the entity to insert hooks for performing actions automatically when the property is accessed. 代理类重写了virtual属性 For example, this mechanism is used to support lazy loading of relationships. The techniques shown in this topic apply equally to models created with Code First and the EF Designer. 在lazy loading中会用到 Most of the time you don't need to be aware of this use of proxies, but there are exceptions: 序列化的时候代理类就不能用了 1. In some scenarios you might want to prevent the Entity Framework from creating proxy instances. For example, when you're serializing entities you generally want the POCO classes, not the proxy classes. One way to avoid serialization problems is to serialize data transfer objects (DTOs) instead of entity objects, as shown in the Using Web API with Entity Framework tutorial. Another way is to disable proxy creation. 2. When you instantiate an entity class using the new operator, you don't get a proxy instance. This means you don't get functionality such as lazy loading and automatic change tracking. This is typically okay; you generally don't need lazy loading, because you're creating a new entity that isn't in the database, and you generally don't need change tracking if you're explicitly marking the entity as Added. However, if you do need lazy loading and you need change tracking, you can create new entity instances with proxies using the Create method of the DbSet class. 3. You might want to get an actual entity type from a proxy type. You can use the GetObjectType method of the ObjectContext class to get the actual entity type of a proxy type instance.
  • 相关阅读:
    COMPUTE BY 子句 cube 子句
    性能计数器 可接受值 或者说参考范围
    我们也来hold住优化SQL SERVER锁的使用
    反编译工具源代码
    图片居中,图片垂直居中,图片水平居中
    SessionStateTempDataProvider类需要启用会话状态(2)
    是我Out了,还是IT市场真井喷了?
    四天玩转 Windows Phone 开发
    从物理结构说sql server 优化
    SEO和百度
  • 原文地址:https://www.cnblogs.com/celery94/p/3910025.html
Copyright © 2020-2023  润新知