Pass 2 arguments to Dataportal.Fetch

Pass 2 arguments to Dataportal.Fetch

Old forum URL: forums.lhotka.net/forums/t/12344.aspx


Brendt posted on Tuesday, February 04, 2014

Good day.

i hope that somebody could help me with this. i am needing to pass 2 parameters to the Dataportal.Fetch method. currently i am passing 1 argument which is an enum type, but i am needing to pass a second optional string parameter to fetch NVLList objects. currently i have this method which works well when passing only 1 argument:

public static NVLList GetList(Common.Enums.TextListEnum emListType)
        {
            return Csla.DataPortal.Fetch<NVLList>(emListType);
        }

but i am needing to do something like this:

public static NVLList GetList(Common.Enums.TextListEnum emListType,[Optional]string Pparam)
        {
            //return Csla.DataPortal.Fetch<NVLList>(emListType,Pparam); <- this does not work
        }

 

i have tried this as well which does not give any Intelli errors but fails when running the code:

public static NVLList GetList(Common.Enums.TextListEnum emListType,[Optional]string Pparam)
        {
            return Csla.DataPortal.Fetch<NVLList>(new Criteria(emListType,Pparam));
        }

 private class Criteria
        {
            public Common.Enums.TextListEnum Arg1 { get; private set; }
            public string Arg2 { get; private set; }
            public Criteria(Common.Enums.TextListEnum arg1, string arg2) { Arg1 = arg1; Arg2 = arg2; }
        }

 

the reason that i am needing to pass the second optional parameter is that i am calling NVLList based on an enum which determines what list i am returning, but at times i need to return a list for certain sql queries based on an ID value which is what i would like to pass in the second optional parameter.

 

any help on this would be greatly appreciated.

JonnyBee replied on Tuesday, February 04, 2014

The latter version should work just fine,.

You add Serializable attribute to Criteria object and if on 4.x you should also use managed properties and inherit from CriteriaBase.

Then have a DataPortal_Fetch method that accepts Criteria object as one single parameter.

Which exception do you get?

Brendt replied on Tuesday, February 04, 2014

thanks JonnyBee.

works like a charm, as always you rock.

Copyright (c) Marimer LLC