How to set the return value of one ObjectDataSource based on another ObjectDataSource

I have two Asp.net ListView controls bound to two different ObjectDataScource controls. Each ODS control refers to "MethodA" and "MethodB".

I want "MethodA" to make one database call and return data for "MethodA" and "MethodB".

I could always "MethodB" make a second call to the database, but that would be inefficient.

I'm not sure if this is the best way.

    [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;
    }

      

+1


a source to share


1 answer


I don't think this is easily possible.

You can ditch the ObjectDatasource and throw it yourself or hack it.

Can a static variable [ThreadLocal] be used in this class and let MethodA put a value in that variable? MethodB could read it.

AND

  [ThreadLocal]
  private DataSet m_cachedAtoB=null;

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

      



Call Reset () from the beginning of your page so that every thread that ASP.NET refines doesn't leave old stale data for the next request. Did I mention this is a hack?

Better solution: It looks like MethodB doesn't take a parameter. So, whatever MethodB requests it, let MethodA extract it and insert it into the HttpCache.

What I did was that my backends are returning a fairly large (10 tables) complete dataset for the web servers with all static data. I had a class there that had things like your Mehtod and Mehtod. But they always chose a dataset. GetDataSet () asked for cahce, and if it was missing, requested the webservice and put it in cahce. Each of my MethodA methods just used LINQ to get information from a large dataset.

Of course, this only works with static data ...

0


a source







All Articles