EntityFramework中的代理是什么意思? [英] What is the proxy meaning in EntityFramework?

查看:99
本文介绍了EntityFramework中的代理是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用 EntityFramework 作为ORM,并且使用此技术没有任何问题.我听说EntityFramework创建了一个代理.我想知道这个ORM创建什么代理?它能做什么?并且,当EF创建时?换句话说,ORM主题中经常使用的代理"一词的含义是什么.

I've used EntityFramework as an ORM in my projects and I don't have any problem in using this technology. I heard EntityFramework creates a proxy. I want to know WHAT proxy this ORM creates? What it does? And, when EF creates it? In the other words, what is the meaning of term "proxy" frequently being used in ORM topics.

推荐答案

ORM世界中的代理是一种自动生成的类型,它是从您的域对象类型继承而来的.代理表示一个实例,该实例尚未用数据库中的数据填充,但仅知道其自己的ID.每当访问映射到数据库的属性时,代理子类都会从数据库执行加载,因此该加载对于客户端代码是透明的.

A proxy in the ORM world is an automatically generated type that inherits from your domain object type. The proxy represents an instance which has not been populated with data from the database yet, but only knows its own ID. Whenever a property which is mapped to the database is accessed, the proxy subclass will carry out the load from the database, so that the load is transparent to the client code.

通常,当您在延迟加载的两个实体之间具有Relationship属性时,就会创建代理.例如.当您访问user.Address属性时,真正返回的是一个地址代理对象.只有在您访问该对象的属性(例如user.Address.StreetName)后,才会加载正确的Address对象.

Proxies are typically created when you have a relationship property between two entities which is lazily loaded. E.g. when you access the user.Address property, what is really returned is an Address proxy object. Only once you access a property of that object (e.g. user.Address.StreetName) the Address object proper will be loaded.

这篇关于EntityFramework中的代理是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆