zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    进程间通信的方式——信号、管道、消息队列、共享内存
    exit()与_exit()的区别(转)
    [Google Codejam] Round 1A 2016
    使用shell脚本自定义实现选择登录ssh
    PHP的反射机制【转载】
    PHP set_error_handler()函数的使用【转载】
    PHP错误异常处理详解【转载】
    php的memcache和memcached扩展区别【转载】
    .htaccess重写URL讲解
    PHP数据库扩展mysqli的函数试题
  • 原文地址:https://www.cnblogs.com/celery94/p/3910025.html
Copyright © 2011-2022 走看看