为什么导航属性必须公开才能创建代理? [英] Why do navigation properties have to be public for a proxy to be created?

查看:107
本文介绍了为什么导航属性必须公开才能创建代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft.com/en-us/library /dd468057.aspx 我读到,我想要更改跟踪代理的所有导航属性需要是 public virtual 。从我的理解,CLR动态创建我的POCO的子类,并重新实现属性以提供所请求的行为。

At http://msdn.microsoft.com/en-us/library/dd468057.aspx I read that all navigation properties for which I would like to have a change tracking proxy need to be public and virtual. From what I understand, the CLR creates subclasses of my POCOs dynamically, and it re-implements the properties to provide the requested behaviour.

为此,我承诺该属性需要要成为 virtual ,它应该具有 protected 或更高的可访问性。但是,如果我想在assemby中使用这些方便,但不想公开它们,我更喜欢他们不要 public 。这导致我有两个问题。

For this I undertand that the property needs to be virtual, and that it should have protected or higher accesability. However, if I want to use these for convenience within the assemby, but don't want to expose them, I prefer them not to be public. Which leads me to two questions.


  1. (为了我的了解发生什么)为什么运行时需要属性 public 而不是 protected internal

(根据我的实际情况)是否有任何解决方法来隐藏导航属性,但仍然具有更改跟踪行为?

(for my actual situation) are there any workarounds to hide the navigation property, but still have the change tracking behaviour?


推荐答案

属性必须是public(和virtual)或protected(和virtual)才能使代理工作。

Properties must be public (and virtual) OR protected (and virtual) for proxies to work.

代理不在您的程序集中预先定义,因此内部不起作用。

Proxies are not pre defined in your assembly, therefore internal won't work.

私人不会因为明显的原因(代理继承自你的班级)。

Private won't work for obvious reasons (proxies inherit from your classes).

这篇关于为什么导航属性必须公开才能创建代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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