NavigationProperties and ProxyCreationEnabled

NavigationProperties and ProxyCreationEnabled

Postby Ansgar » Wed 23 Jul 2014 12:10

Hi all,

I was trying thin following thing:

Code: Select all
      Dim par = New Parent
      Dim ch As New Child
      par.Childs.add(ch)


In the last line an error occured,becausethe navigation property Childs is nothing.
This is the case, because the T4 template provided by DevArt has the following lines:

Code: Select all
If (Not ProxyCreationEnabled) Then
        #> = New HashSet (Of <#= relationType #>)<#+
      End If


If ProxyCreationEnabled is set to true, all navigationproperties looks like this:

Code: Select all
Public Overridable Property TABLENAMEs() As ICollection(Of TABLENAME)

If ProxyCreationEnabled is false then it looks like this:

Code: Select all
Public Overridable Property TABLENAMEs() As ICollection(Of TABLENAME) = New HashSet(Of TABLENAME)

I'm sorry, but I don't really understand that design. Could you please explain it to me.

Thanks a lot.

Ansgar
Ansgar
 
Posts: 10
Joined: Tue 05 Mar 2013 07:25

Re: NavigationProperties and ProxyCreationEnabled

Postby Shalex » Fri 25 Jul 2014 08:50

The dynamic proxy documentation is available at http://msdn.microsoft.com/en-us/data/jj592886.aspx (the "Explicitly creating an instance of a proxy" section demonstates a correct way of creating proxy-class instance).
http://stackoverflow.com/questions/7111109/should-i-enable-or-disable-dynamic-proxies-with-entity-framework-4-1-and-mvc3
We do not create the HashSet instance. The reason is that a class, which is a descendant from a current class, with overridden navigation properties will be created automatically because of using dynamic proxy classes by Entity Framework itself.
Our implementation assumes that if usage of proxy classes is turned on, a user will use proxy classes.
Shalex
Devart Team
 
Posts: 7780
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle