EntityCollection Component generator template

Posts   
 
    
Trig
User
Posts: 96
Joined: 09-Jun-2004
# Posted on: 14-Jun-2004 22:18:33   

I downloaded the EntityCollection Component template from the 3rd Party section earlier today, and after I converted it to VB I noticed that there appears to be an issue with the template. It implements the IListSource interface in order to provide a 'wrapper' around an EntityCollection, but it doesn't seem to do much good to do so in this implementation because you still can't use the IDE to specify databound fields... So, I've made a few changes. It's a VB version, but if there's a desire for it I'd be happy to port the changes back to the C# version.

The only changes (afaik) that were really necessary are these: 1. Changed the type of the <[CaseCamel CurrentEntityName]>s member from IList to <[CurrentEntityName]>Collection so that the IDE knows its a strongly typed collection and can work with the properties in design-time. 2. Changed the return value of ContainsListCollection(). Returning true there implies that the IList we return is collection of collections, like a DataSet. However, we're returning a collection of objects more like a DataTable. I believe when its set to True, VS.NET is looking through the collection for other 'tables' to populate the DataMember field in the same way that when you have a typed DataSet bound to a DataGrid, the DataMember property will show a list of tables in the DataSet.

I also added the default property Item, may or may not be necessary...

Here's the template:

'///////////////////////////////////////////////////////////////
'// This is generated code. If you modify this code, be aware
'// of the fact that when you re-generate the code, your changes
'// are lost. If you want to keep your changes, make this file read-only
'// when you have finished your changes, however it is recommended that
'// you inherit from this class to extend the functionality of this generated
'// class or you modify / extend the templates used to generate this code.
'//
'// Do not try to run this code on another version of the database than the database
'// which was used to generate this code. This means that when you used f.e. SqlServer 2000
'// to generate this code, it is likely that you will not be able to use that code on
'// SqlServer 7 due to SQL syntax mismatches. Most code is generic code which will work
'// with any database, but some code relies on a specific database type/vendor/version used. 
'// This code is located in the DaoClasses which target a specific specified database. Also all
'// classes target a specific specified Dynamic Query Engine (DQE) in the using/imports
'// directives. 
'// 
'// Usage: Drop one of the generated Components on a form and use it as a datasource for data-aware controls.
'//     This will make the structure of the Collection available in the designer (like a Typed DataSet).
'//
'// WARNING: Visual Studio gets confused when components in its toolbox are rebuild. 
'//     The components dissapear from any open forms and all custimization is lost.
'//     make sure all forms with CollectionComponents are closed when rebuilding 
'//     the CollectionComponent assembly and always add a Release build of the 
'//     CollectionComponent to the toolbox
'//     We also made sure the version nr of the CollectionComponent classes did not 
'//     increase everytime we built our generated classes. 
'//     You can set this in AssemblyInfo.cs or put the CollectionClasses
'//     in a separate project.  
'//         
'// USE AT YOUR OWN RISK!!  
'//////////////////////////////////////////////////////////////
'// Code is generated using LLBLGen Pro version: <[LLBLGenVersion]>
'// Code is generated on: <[Time]>
'// Code is generated using templates: <[TemplateName]>
'// Templates vendor: Spruit IT. 
'// Vendor URL: http://www.spruit-it.nl
'// Ported to VB.NET by: Chris Bower
'// Templates version: <[TemplateVersion]>
'//////////////////////////////////////////////////////////////
Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Diagnostics
Imports <[RootNamespace]>.EntityClasses
Imports <[RootNamespace]>.CollectionClasses

Imports SD.LLBLGen.Pro.ORMSupportClasses

Namespace <[RootNamespace]>.CollectionClasses
    <Serializable> _
    Public Class <[CurrentEntityName]>CollectionComponent
        Inherits System.ComponentModel.Component
        Implements IListSource
        Private Components As System.ComponentModel.Container = Nothing
        Protected <[CaseCamel CurrentEntityName]>s As <[CurrentEntityName]>Collection
        
        '/// <summary>
        '/// CTor
        '/// </summary>
        Public Sub New(Container as System.ComponentModel.IContainer)
            Me.<[CaseCamel CurrentEntityName]>s = New <[CurrentEntityName]>Collection()
            Container.Add(Me)
            InitializeComponent()           
        End sub

        Public Sub New()
            Me.<[CaseCamel CurrentEntityName]>s = New <[CurrentEntityName]>Collection()
            InitializeComponent()
                End Sub
        
        <Browsable(False)> _
        Public Property Collection As <[CurrentEntityName]>Collection
            Get
                Return Me.<[CaseCamel CurrentEntityName]>s
            End Get
            Set (Value as <[CurrentEntityName]>Collection)
                Me.<[CaseCamel CurrentEntityName]>s = Value
            End Set
        End Property
        
        <Browsable(False)> _
                Default Public ReadOnly Property Item(ByVal index As Integer) As <[CurrentEntityName]>Entity
                    Get
                        Return Me.<[CaseCamel CurrentEntityName]>s(index)
                    End Get
                End Property

        '/// <summary> 
        '/// Clean up any resources being used.
        '/// </summary>
        Protected Shadows Sub Dispose(Disposing As Boolean)
            If Disposing Then
                If Not IsNothing(Components) Then
                    Components.Dispose()
                End If
            End If
            MyBase.Dispose(Disposing)
        End Sub
        
        #Region "Component Designer generated code"
        '/// <summary>
        '/// Required method for Designer support - do not modify
        '/// the contents of this method with the code editor.
        '/// </summary>
        Private Sub InitializeComponent()
            Components = New System.ComponentModel.Container()
        End Sub
        #End Region
        
        #Region "IListSource Members"

        Public Function  GetList() as IList Implements IListSource.GetList
                    Return me.<[CaseCamel CurrentEntityName]>s
        End Function

        Public Readonly Property ContainsListCollection() as Boolean Implements IListSource.ContainsListCollection
            Get
                Return False 
        End Get
        End Property

        #End Region
    End Class
End Namespace