Paging a TypedView

Posts   
 
    
Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 21-May-2009 09:38:36   

Hi,

I need to page a typed view - in a readable way that is, not using the 100 parameter FetchTypedView overload. For this reason I wanted to create an extension method on the adapter. Ideally I would have something like this:

    public static T FetchTypedView<T>(this DataAccessAdapterBase adapter, int pageIndex, int pageSize)
        where T : ITypedView2, new()
    {
        T view = new T();

// magic here return view; }

but I could settle for something like this too if I only knew how to get fields collection for the first FetchTypedView parameter:

    public static T FetchTypedView<T, E>(this DataAccessAdapterBase adapter, int pageIndex, int pageSize)
        where T : TypedViewBase<E>, new()
        where E : DataRow
    {
        T view = new T();
        DataTable table = view.DataSet.Tables[view.TableName];
        IEntityFields2 fields = null;
        adapter.FetchTypedView(fields, table, null, 0, null, true, null, pageIndex, pageSize);
        return view;
    }

Any ideas how to do it? btw - why is it so hard to execute simple scenarios with LLBLGen - often times I find myself calling overloads with numerous parameters to make basic things work. That makes the code less readable than I'd like it to be.

Please consider adding extension methods for simple scenarios in the next version (maybe you already have them somewhere?).

Robert.

LLBLGen used : v 2.6

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 21-May-2009 09:49:21   

Instead of the TypedViewBase, try using the ITypedView... which has the GetFieldsInfo() which returns the EntityFields2 collection.

Robert.W
User
Posts: 79
Joined: 19-Jun-2007
# Posted on: 21-May-2009 09:57:21   

Thanks, I went throught FetchTypedView overloads code and figured that out (missed TypedViewBase didn't implement ITypedView2). If anyone's interested following method seems to work fine:

    public static T FetchTypedView<T>(this DataAccessAdapterBase adapter, int pageIndex, int pageSize)
        where T : ITypedView2, new()
    {
        T view = new T();
        IEntityFields2 fields = view.GetFieldsInfo();
        adapter.FetchTypedView(fields, view as DataTable, null, 0, null, true, null, pageIndex, pageSize);
        return view;
    }
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 21-May-2009 10:51:34   

You're mostly welcomed and thanks for sharing your code.