SharePoint 2010 - SPWeb.GetSiteData Method strange behaviour.

Hi

Some months ago I faced a case in somehow curious regarding to the method SPWeb.GetSiteData(p) https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getsitedata.aspx . It turns out that the following code snippet was not generating the expected table of items: 

try

{    //Some code rgarding SPSiteDataQuery p                    

    DataTable dt = SPContext.Current.Site.RootWeb.GetSiteData(p);         

   //Some code

}                        

catch (Exception e)

{

}

The issue was that in order to use this method you need to use a explicit SPWEB, so the code should be coded in this way:

 try

  {   //Some code regarding SPSiteDataQuery p

     SPSite Siteh = SPContext.Current.Site;                             

     using (SPWeb Webh = Siteh.OpenWeb())

        {                        

        DataTable dt = Webh.GetSiteData(p);            

        //Some Code

         }

}                       

catch (Exception e) 

{

}

Eventually, to sum up, it seems to be by design (I didn't double check with USA Product Group) but the statistics regarding the items seems to be calculated when you instace the new SPWeb in an explicit way

Thanks.

Kind regards.

Héctor Calvarro Martín. SharePoint Dev. Microsoft Support Engineer for DEV EMEA