<?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 : Generated (Ugly) SQL Problem</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2009 : Generated (Ugly) SQL Problem</description>
  <pubDate>Thu, 16 Apr 2026 07:45:58 -700</pubDate>
  <lastBuildDate>Thu, 25 Mar 2010 06:54:02 -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=1657</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>Generated (Ugly) SQL Problem : Whew.  We are back to 1 problem....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6407#6407</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=308" rel="nofollow">skingaby</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 25-Mar-2010 at 6:54am<br /><br />Whew.  We are back to 1 problem.  The first one.  <br /><br />The View problem turned out to be the key, as kimj had suggested.  We adjusted the Key and the view is returning the correct rows.<br /><br />To anyone else reading this:  When you use a View as a source for an Entity, you MUST ensure that the EF model has the correct Key settings.&nbsp;&nbsp;&nbsp;]]>
   </description>
   <pubDate>Thu, 25 Mar 2010 06:54:02 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6407#6407</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : I am sending you the EDMX via....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6406#6406</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=308" rel="nofollow">skingaby</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 25-Mar-2010 at 6:12am<br /><br />I am sending you the EDMX via. Private Message.<br /><br />Note that we have two situations now.  We worked around the first, and are now presented with a second.  kimj suggested I look at the Key settings in the Model as that might be causing the problem in the new one.  I will explore that.<br /><br />The problems are:<br />1) A complex query with many includes and several conditions, works fine in Dev and QA but fails in Staging and Production when a Date Range filter (i.e. theDate &gt;= StartDate and theDate &lt;= EndDate is used.<br />2) An Oracle View is used as an object source in the model and is not returning the correct number of rows.  ]]>
   </description>
   <pubDate>Thu, 25 Mar 2010 06:12:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6406#6406</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : Hi Simon - Sorry this is happening....</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6404#6404</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 24-Mar-2010 at 5:05pm<br /><br />Hi Simon - Sorry this is happening.&nbsp; Want to bail you out quickly. We need the EDMX ... probably even more than the database. Need to understand the schema and mappings involved in the query. This is probably more important than the sample database (which we'd like, sure).<DIV>&nbsp;</DIV><DIV>Meanwhile, have you tried<strong> removing the INCLUDES and turning query inversion OFF?</strong> These steps should greatly simplify the SQL generated by EF (no ... we don't generate the SQL). They've been known to "cure" EntityFramework SQL generation errors (whatever their cause). We'll worry about getting the related entities once we resolve the misbehavior.</DIV><DIV>&nbsp;</DIV><DIV>It is strange that the query works in Dev and Test but not in Stage. I'm sure you're looking into the differences.</DIV><DIV>&nbsp;</DIV><DIV>Have you tried writing a Console app test of the query ... a way of taking Silverlight out of the equation (not that I think it is to blame).</DIV><DIV>&nbsp;</DIV><DIV>We will get you through this!</DIV><DIV>&nbsp;</DIV><DIV>W</DIV><DIV>&nbsp;</DIV><DIV><DIV>Aside: I understand you use Oracle. I was going to suggest that you use SQL Profiler to look at the generated SQL; it's often as helpful or more helpful than our log.&nbsp;I don't know what the equivalent Oracle tool is.</DIV><DIV>&nbsp;</DIV><DIV>Aside: although it won't make a difference to your current problem, for the future, I think you will find that you don't need both of the following Includes because the second subsumes the first:</DIV><DIV>&nbsp;</DIV><DIV><EM>&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealConfContacts)<BR>&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealConfContacts + "." + DealConfContact.EntityPropertyNames.Contact)<BR></EM></DIV><DIV>In a multi-leg Include, intermediate legs are included automatically:</DIV></DIV>]]>
   </description>
   <pubDate>Wed, 24 Mar 2010 17:05:44 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6404#6404</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : We&amp;#039;ll need to get a copy...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6402#6402</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=477" rel="nofollow">ting</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 24-Mar-2010 at 2:05pm<br /><br />We'll need to get a copy of the database and the query to take a look.&nbsp; I will have someone contact you directly about this.]]>
   </description>
   <pubDate>Wed, 24 Mar 2010 14:05:11 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6402#6402</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : It turned out that the logTraceString...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6401#6401</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=531" rel="nofollow">midnit</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 24-Mar-2010 at 7:48am<br /><br />It turned out that the logTraceString was on the wrong datasource so I have now&nbsp;seen the query&nbsp;for the single table and it is as expected. When you run this query on the database you get 232 records, but again we only get 187 when ran through IdeaBlade. We need some direction here.<span style="font-size:10px"><br /><br />Edited by midnit - 24-Mar-2010 at 7:49am</span>]]>
   </description>
   <pubDate>Wed, 24 Mar 2010 07:48:21 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6401#6401</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : I work with skingaby and we have...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6400#6400</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=531" rel="nofollow">midnit</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 24-Mar-2010 at 7:04am<br /><br />I work with skingaby and we have come across other strange "results". We have a table that has no relationships, no indexes, no conditions that should return the full set of results but the table consists of 232 records and once pulled through to Silverlight we get 187. The log does not report the query created (is there a way to make it?) it only says: <DIV>source="IdeaBlade.EntityModel.Server.EntityServer:Fetch"&gt;Fetch ... value(IdeaBlade.EntityModel.EntityQueryProxy`1&#091;Png.GcsAg.Model.Deal.GmsCustomerComboitem&#093;)</DIV><DIV>&nbsp;</DIV><DIV>Going through Entity Developer and retrieve the data I get all the records.</DIV><DIV>&nbsp;</DIV><DIV>And in regard to the above issue, it doesn't matter which date condition you leave off, its only when you combine the two that the issue occurs.</DIV><DIV>&nbsp;</DIV><DIV>We are quickly getting to the point that we cannot trust the application because without meticulous comparison of what IdeaBlade is returning us against whats actually in the database we have no idea if what we are seeing is right.</DIV>]]>
   </description>
   <pubDate>Wed, 24 Mar 2010 07:04:09 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6400#6400</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : The original LINQ query was doing...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6397#6397</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=308" rel="nofollow">skingaby</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 23-Mar-2010 at 6:03am<br /><br />The original LINQ query was doing a date range filter FromDate and ToDate.<br />We ended up working around the problem by changing that to pull all entities .Where(c =&gt; c.DealSnapShot.FlowDateEnd &gt;= filter.FlowDateStart) &#091;i.e., only one of the range boundaries), and then looping through the results and adding the ones where item.FlowDateStart &lt;= filter.FlowDateEnd to a collection for binding. <br />So, we didn't fix the problem at all, we simply sidestepped it.]]>
   </description>
   <pubDate>Tue, 23 Mar 2010 06:03:52 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6397#6397</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : Hi Simon,  1) The Entity Framework...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6333#6333</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=477" rel="nofollow">ting</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 08-Mar-2010 at 5:04pm<br /><br />Hi Simon,<DIV>&nbsp;</DIV><DIV>1)&nbsp; The Entity Framework dynamically generates the SQL based on the LINQ expression tree that is passed to it from DevForce.&nbsp; Depending on the order and structure of the expression tree, the generated SQL may differ slightly.</DIV><DIV>&nbsp;</DIV><DIV>2)&nbsp; It is possible, but I believe unlikely that the Entity Framework would generate different SQL depending on the indexing.</DIV><DIV>&nbsp;</DIV><DIV>3)&nbsp; We have not changed anything that would affect SQL generation in DevForce 5.2.5 or 5.2.6.</DIV><DIV>&nbsp;</DIV><DIV>4)&nbsp; As for debugging this, can you check to see that the full query (the one that includes the&nbsp;date range) generates the same SQL in both environments?&nbsp; If the SQL is the same, you'll want to check your database for bad data (perhaps in that date column?)</DIV><DIV>&nbsp;</DIV><DIV>Let us know what you find.&nbsp; Thanks!</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Mon, 08 Mar 2010 17:04:28 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6333#6333</guid>
  </item> 
  <item>
   <title>Generated (Ugly) SQL Problem : Attachment:  posting.txt  We had...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6249#6249</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=308" rel="nofollow">skingaby</a><br /><strong>Subject:</strong> 1657<br /><strong>Posted:</strong> 23-Feb-2010 at 8:08am<br /><br />Attachment:  <a href="uploads/308/posting.txt" target="_blank">posting.txt</a><br /><br />We had to pull the plug on a production deployment yesterday because of an anomaly discovered in the 11th hour in our Staging (pre-production) environment.<br />An Entity Query that works perfectly in our Dev and Test environments, was not returning all the expected records in the Staging environment.<br /><br />We are using IdeaBlade DevForce for Silverlight (v5.2.4), Devart dotConnect for Oracle (v5.35.62), and the MS Entity Framework (.Net 3.5).<br /><br />I have an entity query like so:<br /><br /><table width="99%"><tr><td><pre class="BBcode">public IEntityQuery ConfirmationsFilteredQuery(object&#091;&#093; parameters)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var filter = (BasicFilter)parameters&#091;0&#093;;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var confirmationsQuery = this.ConfirmationsBaseQuery(null);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return confirmationsQuery<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Where(c =&gt; c.DealSnapShot.FlowDateEnd &gt;= filter.FlowDateStart)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Where(c =&gt; c.DealSnapShot.FlowDateStart &lt;= filter.FlowDateEnd)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Where(c =&gt; c.ConfStatusId == (long)filter.SelectedStatus)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.With(QueryStrategy.DataSourceOnly);<br />}<br /><br />private IEntityQuery&lt;DealConfirmation&gt; ConfirmationsBaseQuery(object&#091;&#093; parameters)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var em = (ConfirmationEntityManager)this.PersistenceContext.EntityManager;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return em.DealConfirmations<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealConfContacts)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealConfContacts + "." + DealConfContact.EntityPropertyNames.Contact)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealSnapShot + "." + DealSnapShot.EntityPropertyNames.DealPricingSnapShots)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealSnapShot + "." + DealSnapShot.EntityPropertyNames.DealTrxPricingSnapShots)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Include(DealConfirmation.EntityPropertyNames.DealSnapShot + "." + DealSnapShot.EntityPropertyNames.DealTrxSnapShots);<br />}</pre></td></tr></table><br /><br />When I execute this query, the generated SQL looks like (hold your nose) this:<br /><br /><table width="99%"><tr><td><pre class="BBcode">SELECT "UnionAll3".C2 AS C1,<br />&nbsp;&nbsp;&nbsp;"UnionAll3".C3 AS C2,<br />&nbsp;&nbsp;&nbsp;...See attached file...<br /></pre></td></tr></table><br /><br />The problem is that this query only returns some of the records that should be returned.  And only in one of our database environments.  We have done the obvious things and all of the tables are the same.  There are some differences in indexes and constraints between the database where the query works and where it doesn't.<br />Also, if we comment out the one of the date range where clause, i.e.:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//.Where(c =&gt; c.DealSnapShot.FlowDateStart &lt;= filter.FlowDateEnd)<br />The resulting query does return all the expected records in all database environments.  Here is what the working query looks like:<br /><br /><table width="99%"><tr><td><pre class="BBcode">SELECT "UnionAll3".C2 AS C1,<br />&nbsp;&nbsp;&nbsp;"UnionAll3".C3 AS C2,<br />&nbsp;&nbsp;&nbsp;...See attached file...<br /></pre></td></tr></table><br /><br />A diff. on these two SQL files shows some obvious differences re: the where clause, and this one weird difference:<br /><br /><table width="99%"><tr><td><pre class="BBcode">"UnionAll3".C71 AS C70,<br />"UnionAll3".C1 AS C71,</pre></td></tr></table><br /><br />vs.<br /><br /><table width="99%"><tr><td><pre class="BBcode">"UnionAll3".C1 AS C70,<br />"UnionAll3".C71 AS C71,</pre></td></tr></table><br /><br />So, my questions are as follows:<br />1) Which tool actually creates this SQL statement?  <br />2) Is it possible that differences in Indexes on the tables could alter the way the SQL Generator generates the SQL?<br />3) Is this fixed in a newer release?<br />4) How can I fix/debug this?<br /><br />Thanks,<br />Simon<br /><br /><span style="font-size:10px"><br /><br />Edited by skingaby - 23-Feb-2010 at 8:16am</span>]]>
   </description>
   <pubDate>Tue, 23 Feb 2010 08:08:40 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=1657&amp;PID=6249#6249</guid>
  </item> 
 </channel>
</rss>