Page 1 of 1

NavigationProperties and ProxyCreationEnabled

Posted: Wed 23 Jul 2014 12:10
by Ansgar
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

Re: NavigationProperties and ProxyCreationEnabled

Posted: Fri 25 Jul 2014 08:50
by Shalex
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/7111 ... 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.