3

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.

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. (for my understanding of what is going on) why does the runtime require the properties to be public rather than protected or internal?

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

Martijn
  • 11,964
  • 12
  • 50
  • 96

1 Answers1

2

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

Danny Varod
  • 17,324
  • 5
  • 69
  • 111
  • 1
    I could have sworn I tried protected, and it didn't work. I'll come back to this after I tried again – Martijn Jun 18 '12 at 13:08
  • I have tried it with the POCO generator. It is especially useful for the collection's setters. – Danny Varod Jun 18 '12 at 14:23
  • The specific reason it doesn't work is that you cannot override an internal virtual property outside of the assembly, as Danny states. You can achieve the desired result by marking your property protected internal. – Evan Machusak Dec 20 '13 at 18:47
  • Please add that you need to configure the protected navigation first. So like HasMany(t => t.ProtectedVirtualNavigationCollection).WithRequred(t => t.Source) – verbedr Dec 04 '19 at 08:25