views:

416

answers:

1

I have two Asp.net ListView Controls bound to two different ObjectDataScource Controls. Each ODS control references 'MethodA' and 'MethodB'.

I want 'MethodA' to make one call the the database and return data for both 'MethodA' and 'MethodB'.

I could always have 'MethodB' make a second call to the database, but that would not be efficient.

I am not sure the best way to accomplish this.

    [DataObjectMethod(DataObjectMethodType.Select)]
    public List<int> MethodA(int input)
    {
        List<int> a = new List<int>();
        List<string> b = new List<string>();
        ///
        /// Make one call to database
        /// returns: List<int> and List<string>
        /// set 'a' and 'b' values.

        return a;
    }
    [DataObjectMethod(DataObjectMethodType.Select)]
    public List<string> MethodB()
    {
        List<string> b = new List<string>();
        ///
        /// When MethodA is called set 'b'
        ///
        return b;
    }
A: 

I don't think that this is easily possible.

You could drop ObjectDatasource and roll it on your own or hack around it.

Maybe use a [ThreadLocal] static variable in that class and let MethodA put the value into that variable? MethodB could read it.

And a

  [ThreadLocal]
  private DataSet m_cachedAtoB=null;

  public static void Reset()
  {
     m_cachedAtoB=null;
  }

Call Reset() from the start of your page so that each thread that is recycled by ASP.NET will not leave old stale data for the next request. Did I mention that this is a hack?

Better solution: It seems like that MethodB does not take a parameter. So whatever it is that MethodB queries, let MethodA fetch it and push it into a HttpCache.

What I did was that my backend returend a quite big (10 tables) complete dataset to the webservers with all static data. There I had a class that had also things like your MehtodA and MehtodB. But they always fetched the dataset. GetDataSet() queried the cahce and if it was missing queried the webservice and put it in the cahce. Every of my MethodA methods simply used LINQ to get stuff from the big dataset.

Of course that only works with static data...

Christian
the data I am using is not large just complicated to calculate, I want to avoid calculating it twice for the same input value. I was thinking about putting the data for MethodB in the Session.
TonyAbell