Invalid Cast?

Posts   
 
    
Darwin avatar
Darwin
User
Posts: 38
Joined: 12-Apr-2005
# Posted on: 08-Aug-2005 22:18:44   

I have the following class which inheriting from a Typed View:


using System;
using System.Runtime.Serialization;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace ExecutempsSW.Windows.Service.Interface.Browse
{
    /// <summary>
    /// Summary description for ClientBrowse.
    /// </summary>
    public class ClientBrowse : ExecutempsSW.Data.TypedViewClasses.ClientBrowseTypedView
    {
        public ClientBrowse(string sessionID): base()
        {
            this._SessionID = sessionID;
        }
        public ClientBrowse(IRelationPredicateBucket filter, IGroupByCollection group, ISortExpression sort, int maxItems, bool allowDuplicates, int pageSize, int pageNumber, string sessionID): base()
        {
            this._Filter = filter;
            this._Group = group;
            this._Sort = sort;
            this._MaxItems = maxItems;
            this._PageNumber = pageNumber;
            this._PageSize = pageSize;
            this.AllowDuplicates = allowDuplicates;
            this._SessionID = sessionID;
            this.FetchData();
        }
        protected ClientBrowse(SerializationInfo info, StreamingContext context, string sessionID):base(info, context)
        {
            this._SessionID = sessionID;
            this.FetchData();
        }
        public virtual bool FetchData()
        {
            return false;
        }
        public virtual bool FetchData(int MaxItems)
        {
            this._MaxItems = MaxItems;
            return this.FetchData();
        }
        public virtual bool FetchData(int PageSize, int PageNumber)
        {
            this._PageSize = PageSize;
            this._PageNumber = System.Math.Min(PageNumber, this.TotalRows());
            return this.FetchData();
        }
        public virtual bool FetchData(int currentKey, int pageSize, int pageAboveOrBelowCurrentKey)
        {
            this._PageSize = PageSize;
            this._PageNumber = System.Math.Min(PageNumber, this.TotalRows());
            return this.FetchData();
        }
        public virtual int CurrentKey()
        {
            return 0;
        }
        public virtual int TotalRows()
        {
            return 0;
        }
        public virtual bool PageUp()
        {
            return this.FetchData(PageSize, ++_PageNumber);
        }
        public virtual bool PageDown()
        {
            return this.FetchData(PageSize, --_PageNumber);
        }
        private IRelationPredicateBucket _Filter = new  RelationPredicateBucket();
        public IRelationPredicateBucket Filter
        {
            get{return _Filter;}
        }
        private IGroupByCollection _Group = new GroupByCollection();
        public IGroupByCollection Group
        {
            get{return _Group;}
        }
        private ISortExpression _Sort = new SortExpression();
        public ISortExpression Sort
        {
            get{return _Sort;}
        }
        private int TotalPages
        {
            get{return (this.TotalRows() / this.PageSize) + 1;}
        }
        protected int _PageSize = 0;
        public int PageSize
        {
            get{return _PageSize;}
        }
        protected int _PageNumber = 1;
        public int PageNumber
        {
            get{return _PageNumber;}
        }
        protected int _MaxItems = 0;
        public int MaxItems
        {
            get{return _MaxItems;}
        }
        protected string _SessionID;
        public string SessionID
        {
            get{return _SessionID;}
        }
        protected bool _AllowDuplicates = false;
        public bool AllowDuplicates
        {
            get{return _AllowDuplicates;}
            set{_AllowDuplicates = value;}
        }
    }
}

Which is inherited by this class:


using System;
using System.Runtime.Serialization;
using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.LLBLGen.Pro.DQE;

namespace ExecutempsSW.Windows.Service.Browse
{
    public class ServerClientBrowse: ExecutempsSW.Windows.Service.Interface.Browse.ClientBrowse
    {
        public ServerClientBrowse(string SessionID): base(SessionID)
        {
        }
        public ServerClientBrowse(IRelationPredicateBucket filter, IGroupByCollection group, ISortExpression sort, int maxItems, bool allowDuplicates, int pageSize, int pageNumber, string SessionID): base(filter, group, sort, maxItems, allowDuplicates, pageSize, pageNumber, SessionID)
        {
        }
        protected ServerClientBrowse(SerializationInfo info, StreamingContext context, string sessionID):base(info, context, sessionID)
        {
        }
        public override bool FetchData()
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            adapter.FetchTypedView(this.GetFieldsInfo(), this, this.Filter, this.MaxItems, this.Sort, false, this.Group, this.PageNumber, this.PageSize);
            return true;
        }
        public override int  TotalRows()
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            return adapter.GetDbCount(this.GetFieldsInfo(), this.Filter, this.Group, false);
        }
    }
}

I get an Invalid Cast Exception when this call is made:


public Interface.Browse.ClientBrowse GetClientBrowse(string sessionID)
{
    return ((Interface.Browse.ClientBrowse)new Browse.ServerClientBrowse(sessionID).Clone());
}


Any clues?

Thanks, Darwin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 09-Aug-2005 10:08:41   

Clone() is the DataTable.Clone() method, which returns a DataTable, which is thus not of a derived type of DataTable.

Frans Bouma | Lead developer LLBLGen Pro