Need help with this collection class

Posts   
 
    
hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 05-Jul-2005 15:52:32   

My errors are on the index override and save method


public class DependencyCollection
{
    #region Member Variables            
    //private AppDependencyCollection _List = null; 
    private EntityCollection _List = null;
    #endregion

    #region Properties
    public Dependency this[int index]
    {
        get { return new Dependency( _List[index] ); } 
    }
    public int Count
    {
        get { return _List.Count; } 
    }
    internal bool IsDirty
    {
        get { return _List.ContainsDirtyContents; } 
    }
            #endregion

    #region Constructors
    //internal DependencyCollection( AppDependencyCollection list ) 
    internal DependencyCollection( EntityCollection list ) 
    {
                   _List = list; 
                }
    #endregion
                
    #region Methods
    internal void Add( Dependency dep )
    { 
        _List.Add( dep._DependencyEntity );
    }

    internal void RemoveAt( int index ) 
    {
        _List.RemoveAt( index );
    }
    
                internal void Save() 
    {       
        //TODO: SaveEntityCollection of Adapter???
        _List.SaveMulti( false );
    }
    #endregion
}

(Otis) please post code between code tags. Thanks.

hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 05-Jul-2005 16:32:13   

This is the second part of the original post that I forgot to put in.


public class Dependency
{
    #region Member Variables
    //internal readonly AppDependencyEntity _DependencyEntity = null;       
    internal readonly AppDependencyEntity _DependencyEntity = null; 
    #endregion

    #region Properties / Accessors              
    // AppId is readonly
    public int AppId {get { return _DependencyEntity.AppId; } }

    public string FileName {get { return _DependencyEntity.FileName; }      set { _DependencyEntity.FileName = value; } }
    public string SourcePath {get { return _DependencyEntity.SourcePath; }  set { _DependencyEntity.SourcePath = value; } }
    public string InstallPath { get { return _DependencyEntity.InstallPath; }   set { _DependencyEntity.InstallPath = value; } }
    #endregion

    #region Constructors / Destructor
    public Dependency ( AppDependencyEntity entity ) 
    {
        this._DependencyEntity = entity; 
    }
    public Dependency ( string fileName, string sourcePath, string installPath ) 
    {
        _DependencyEntity = new AppDependencyEntity();
        _DependencyEntity.FileName = fileName;
        _DependencyEntity.SourcePath = sourcePath;
        _DependencyEntity.InstallPath = installPath;
    }
    #endregion

    #region Methods
    #endregion

    #region Overrides
    #endregion

    #region Interfaces
    #endregion

    #region Subclasses
    #endregion

}

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 05-Jul-2005 19:24:19   

hommels wrote:

My errors are on the index override and save method

public class DependencyCollection { #region Member Variables //private AppDependencyCollection _List = null; private EntityCollection _List = null; #endregion

#region Properties
public Dependency this[int index]
{
    get { return new Dependency( _List[index] ); } 
}
public int Count
{
    get { return _List.Count; } 
}
internal bool IsDirty
{
    get { return _List.ContainsDirtyContents; } 
}
        #endregion

#region Constructors
//internal DependencyCollection( AppDependencyCollection list ) 
internal DependencyCollection( EntityCollection list ) 
{
               _List = list; 
            }
#endregion

#region Methods
internal void Add( Dependency dep )
{ 
    _List.Add( dep._DependencyEntity );
}

internal void RemoveAt( int index ) 
{
    _List.RemoveAt( index );
}

            internal void Save() 
{       
    //TODO: SaveEntityCollection of Adapter???
    _List.SaveMulti( false );
}
#endregion

}

Can you describe what the errors are? In DependencyCollection.Save, I noticed that you're using a SelfServicing method (.SaveMulti()) in what appears to be an Adapter implementation. You'll want to substitute out .SaveMulti() for Adapter.SaveEntitycollection().

Jeff...

hommels
User
Posts: 23
Joined: 01-Jul-2005
# Posted on: 05-Jul-2005 19:42:42   

I fixed the save method but index override says that List is an ivalid argument

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 05-Jul-2005 20:49:05   

Please specify what your errors are, if they're compile errors or runtime exceptions, and if you get runtime exceptions, please specify a callstack / stacktrace which shows what the call path was.

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 05-Jul-2005 20:56:10   

hommels wrote:

I fixed the save method but index override says that List is an ivalid argument

Try this:


 #region Properties
    public Dependency this[int index]
    {
        get { return new Dependency( (AppDependencyEntity)_List[index] ); }
    }

I'm not sure if that's your problem, but give it a go. Remember that the items stored in the Adapter EntityCollections are IEntity2s, not typed entities.

Jeff...