The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Foreign key relationships with non-ES tables

Last post 03-05-2008, 7:09 AM by ryansalt. 3 replies.
Sort Posts: Previous Next
  •  03-05-2008, 4:17 AM 8267

    Foreign key relationships with non-ES tables

    I'm having a problem with the generated code for DNN where the table has a foreign key relationship to another table for which i'm not generating EntitySpaces code, such as the default DNN tables.

    E.g. If one of my tables has a foreign key ModuleId which references the Modules table, the generated code is failing to build because of "DNNModules is not defined errors." Obviously i don't need to build code for the Modules table, so what's the solution here? Remove all the foreign keys?

    In the code below DnnModules is underlined as an error. 

     

    Code:
    #Region "UpToDnnModulesByModuleId - Many To One"
    ''' <summary>
    ''' Many to One
    ''' Foreign Key Name - FK_dnn_otv_Addresses_dnn_Modules
    ''' </summary>
    <XmlIgnore()> _
    Public Property UpToDnnModulesByModuleId As DnnModules

    Get
    If Me
    ._UpToDnnModulesByModuleId Is Nothing _
    AndAlso Not ModuleId.Equals(Nothing) _

    Me._UpToDnnModulesByModuleId = New DnnModules()
    Me._UpToDnnModulesByModuleId.es.Connection.Name = Me.es.Connection.Name
    Me.SetPreSave("UpToDnnModulesByModuleId", Me._UpToDnnModulesByModuleId)
    Me._UpToDnnModulesByModuleId.Query.Where(Me._UpToDnnModulesByModuleId.Query.ModuleID.Equal(Me.ModuleId))
    Me._UpToDnnModulesByModuleId.Query.Load()
    End If

    Return Me
    ._UpToDnnModulesByModuleId
    End Get

    Set
    (ByVal value As DnnModules)
    Me.RemovePreSave("UpToDnnModulesByModuleId")


    If value Is Nothing Then

    Me
    .ModuleId = Nothing
    Me
    ._UpToDnnModulesByModuleId = Nothing
    Else

    Me
    .ModuleId = value.ModuleID
    Me._UpToDnnModulesByModuleId = value
    Me.SetPreSave("UpToDnnModulesByModuleId", Me._UpToDnnModulesByModuleId)
    End If

    End Set

    End Property
    #End Region


    There is also a problem where I have a table Shipments which includes ShipToAddress and ShipFromAddress both of which are foreign keys referencing the Addresses table. Generating code for the Addresses table creates "DNNShipments" is not defined errors, but there is no reference to the Shipments table in the Addresses table. Isn't this backwards?

     

  •  03-05-2008, 5:09 AM 8269 in reply to 8267

    Re: Foreign key relationships with non-ES tables

    If you are going to use the hierarchical model then you must generated classes for all tables that are connected. This is hard to do in DNN because it can be lots of tables you may or may not know about at code generation time. To alleviate this I usually uncheck the generate hierarchical model in the advanced options of the master generated template, and handle this with a view/code/join etc.

    Regards,

    Scott Schecter
    EntitySpaces | My Site
  •  03-05-2008, 6:01 AM 8271 in reply to 8269

    Re: Foreign key relationships with non-ES tables

    Scott is correct, however this is something we are going to address also, we will let you choose which tables to include in the hierarchical model so that it only reaches out to those you select. This might make it into ES2008 in fact.
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  03-05-2008, 7:09 AM 8274 in reply to 8271

    Re: Foreign key relationships with non-ES tables

    Ah-ha! Unchecking the Hierarchal model has fixed this issue for me. Thanks!
View as RSS news feed in XML