<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Subqueries across multiple datasource keys</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce Classic : Subqueries across multiple datasource keys</description>
  <pubDate>Mon, 13 Apr 2026 04:08:52 -700</pubDate>
  <lastBuildDate>Tue, 28 Aug 2007 20:52:35 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=390</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Subqueries across multiple datasource keys : Works great David, thanks! Much...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=1012#1012</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=133" rel="nofollow">joshpainter</a><br /><strong>Subject:</strong> 390<br /><strong>Posted:</strong> 28-Aug-2007 at 8:52pm<br /><br />Works great David, thanks!&nbsp; Much cleaner...]]>
   </description>
   <pubDate>Tue, 28 Aug 2007 20:52:35 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=1012#1012</guid>
  </item> 
  <item>
   <title>Subqueries across multiple datasource keys : The standard and recommended solution...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=1009#1009</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=23" rel="nofollow">davidklitzke</a><br /><strong>Subject:</strong> 390<br /><strong>Posted:</strong> 28-Aug-2007 at 4:57pm<br /><br /><P><FONT face="Verdana, Arial, Helvetica, sans-serif" size=3>The standard and recommended solution to the problem is to use two different span queries to get the data from the two databases, then use a cache-only query to get all of the data into the PersistenceManager cache.&nbsp; In the example below, the Contractor and AddressContractor tables are in two different databases.</FONT></P><DIV><FONT face="Verdana, Arial, Helvetica, sans-serif" size=4></FONT>&nbsp;</DIV><DIV><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Since cross-datasource spans (and subqueries) are not allowed, you can get around this by ensuring all the relevant entities are in the cache. Although this brings more data in than if all the&nbsp;tables were in one&nbsp;db, this is the only concession to cross-data source queries that is necessary. You can then perform your query using a query strategy of CacheOnly.<?:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Your query will work with the following slight modifications:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Pre-load the cache with the entities associated with the query, e.g. Contractor and AddressContractor. <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">You can do this in a variety of ways, the simplest (but also the one that retrieves the most records) is:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>mPersMgr.GetEntities(Of Contractor)()<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="FONT-FAMILY: 'Courier New'">mPersMgr.GetEntities(Of AddressContractor)()</SPAN><o:p></o:p></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Modify your original query to perform a cache-only operation: <o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="FONT-FAMILY: 'Courier New'">aContractor = mPersMgr.GetEntity(pQuery, <SPAN style="COLOR: teal">QueryStrategy</SPAN>.CacheOnly)</SPAN><o:p></o:p></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">Now, if you had a case where you were only filtering by either the parent or the child (in your original case you are filtering by both so this wouldn’t work), you could use a GetParents or GetChildren call across the data sources.<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">For example (removed filter on Contractor):<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'">select</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"> <SPAN style="COLOR: gray">*</SPAN> <SPAN style="COLOR: blue">from</SPAN> tblContractor<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: gray; FONT-FAMILY: 'Courier New'">left</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"> <SPAN style="COLOR: gray">join</SPAN> tblAddressContractor ac <SPAN style="COLOR: blue">on</SPAN> ContractorID <SPAN style="COLOR: gray">=</SPAN> ac<SPAN style="COLOR: gray">.ContractorID</SPAN><o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: gray; FONT-FAMILY: 'Courier New'">left</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"> <SPAN style="COLOR: gray">join</SPAN> tblAddress a <SPAN style="COLOR: blue">on</SPAN> ac<SPAN style="COLOR: gray">.</SPAN>AddressID <SPAN style="COLOR: gray">=</SPAN> a<SPAN style="COLOR: gray">.</SPAN>AddressID<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'">where</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"> ac<SPAN style="COLOR: gray">.</SPAN>TypeID <SPAN style="COLOR: gray">=</SPAN> 3<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><FONT face="Times New Roman">The corresponding query in code:<o:p></o:p></FONT></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'">Dim</SPAN><SPAN style="FONT-FAMILY: 'Courier New'"> pQuery <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> RdbQuery(<SPAN style="COLOR: blue">GetType</SPAN>(AddressContractor))<o:p></o:p></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="COLOR: blue; FONT-FAMILY: 'Courier New'"><o:p><FONT size=3>&nbsp;</FONT></o:p></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: green">'Get filtered AddressContractors</SPAN><o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>pQuery.AddClause(AddressContractor.TypeIDEntityColumn, EntityQueryOp.EQ, <SPAN style="COLOR: red">3</SPAN>)<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: blue">Dim</SPAN> addressContractors <SPAN style="COLOR: blue">As</SPAN> EntityList(Of AddressContractor) = mPersMgr.GetEntities(Of AddressContractor)(pQuery)<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><FONT size=3><SPAN style="COLOR: green; FONT-FAMILY: 'Courier New'">'Call GetParent(s), passing in the intermediate result, “addressContractors”, because there is no other constraint on “Contractor”</SPAN><SPAN style="COLOR: blue"><FONT face="Times New Roman"> <o:p></o:p></FONT></SPAN></FONT></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><SPAN style="FONT-FAMILY: 'Courier New'"><FONT size=3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style="COLOR: blue">Dim</SPAN> contractors <SPAN style="COLOR: blue">As</SPAN> EntityList(Of Contractor) = mPersMgr.GetParents(addressContractors, EntityRelations.Contractor_AddressContractor)<o:p></o:p></FONT></SPAN></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P><P =Ms&#111;normal style="MARGIN: 0in 0in 0pt"><o:p><FONT face="Times New Roman" size=3>&nbsp;</FONT></o:p></P></DIV>]]>
   </description>
   <pubDate>Tue, 28 Aug 2007 16:57:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=1009#1009</guid>
  </item> 
  <item>
   <title>Subqueries across multiple datasource keys : I just found out that you can&amp;#039;t...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=999#999</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=133" rel="nofollow">joshpainter</a><br /><strong>Subject:</strong> 390<br /><strong>Posted:</strong> 28-Aug-2007 at 2:43pm<br /><br />I just found out that you can't write subqueries for entities generated from different datasource keys.&nbsp; I want to explain my work-around and see if anybody can think of a better way.<DIV>&nbsp;</DIV><DIV>My screen has a simple search box and then a grid underneath that displays the search results.&nbsp; One of the fields a user can search on is "Customer Name."&nbsp; </DIV><DIV>&nbsp;</DIV><DIV>My model looks like this:</DIV><DIV>&nbsp;</DIV><DIV>VisitReport.CrmAccount.Name</DIV><DIV>&nbsp;</DIV><DIV>A VisitReport exists in our "main" database, and then CrmAccount represents an account in our CRM database.&nbsp; Name is a property on CrmAccount.</DIV><DIV>&nbsp;</DIV><DIV>It would have been nice if subqueries worked across datasources, cause then I could have done this query easily.&nbsp; However, what I ended up with is using the ListManager.&nbsp; So when the user first pulls up the screen, we get all VisitReports and attach a ListManager to that EntityList.&nbsp; The Predicate defined for the ListManager checks to see that searchTextbox.Text is contained in VisitReport.CrmAccount.Name.</DIV><DIV>&nbsp;</DIV><DIV>Now as the user types, I've wired up the searchTextbox.Changed event to simply reset the resultsList.ListManager to itself, like so:</DIV><DIV>&nbsp;</DIV><DIV>resultsList.ListManager = resultsList.ListManager;</DIV><DIV>&nbsp;</DIV><DIV>It seems that simply setting this propery forces the ListManager to re-evaluate the list.</DIV><DIV>&nbsp;</DIV><DIV>So, the question - is there an easier/better way to do what I'm trying to do?</DIV>]]>
   </description>
   <pubDate>Tue, 28 Aug 2007 14:43:47 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=390&amp;PID=999#999</guid>
  </item> 
 </channel>
</rss>