<?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 : Save a Query</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2012 : Save a Query</description>
  <pubDate>Fri, 10 Apr 2026 22:33:24 -700</pubDate>
  <lastBuildDate>Mon, 12 Aug 2013 11:28:05 -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=4265</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>Save a Query : Thanks smi-mark, your suggestion...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16715#16715</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=452" rel="nofollow">ken.nelson</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 12-Aug-2013 at 11:28am<br /><br />Thanks smi-mark, your suggestion worked, although I still had to add TypeWrapper as a known type for whatever reason.<br /><br />Thanks!]]>
   </description>
   <pubDate>Mon, 12 Aug 2013 11:28:05 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16715#16715</guid>
  </item> 
  <item>
   <title>Save a Query : Ah okay, I&amp;#039;ll give that a...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16713#16713</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=452" rel="nofollow">ken.nelson</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 12-Aug-2013 at 8:37am<br /><br />Ah okay, I'll give that a shot. The post that was linked seems to indicate that converting the query's Expression to a SerializedExpression should work.<br /><em><br />From <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=3187&PID=12343#12343" target="_blank">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&PID=12343#12343</a><br /></em><br /><table width="99%"><tr><td class="BBquote"><br />You could instead build up the dynamic query on your client and pass the query expression to your server method.  It would look something like this:<br /><br />var p1 = PredicateBuilder.Make&lt;Product&gt;(p =&gt; p.Discontinued == false);<br />var ss = new SortSelector(typeof(Product), "ProductName");<br />var query = em.Products.Where(p1).OrderBySelector(ss);<br /><br />var exp = SerializedExpression.ToSerializedExpression(query.Expression);<br /></td></tr></table><br />]]>
   </description>
   <pubDate>Mon, 12 Aug 2013 08:37:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16713#16713</guid>
  </item> 
  <item>
   <title>Save a Query :  We don&amp;#039;t save queries but...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16710#16710</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=449" rel="nofollow">smi-mark</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 11-Aug-2013 at 12:26pm<br /><br />We don't save queries but we do pass expressions to the server.<br><br>An example would be something like:<br><br><table width="99%"><tr><td class="BBquote"><br>Expression&lt;Func&lt;Customer, bool&gt;&gt; filter = c =&gt; c.Name == "bob";<br>var expr = SerializedExpression.ToSerializedExpression(filter);<br></td></tr></table><br><br>We can then pass expr to our remote server method, and I assume you can simply save it on your end. <br><br>Hope that helps.<br><br>One last piece that I should mention. We had to add SerializedExpression to the list of known types. We do it like this:<br><br><table width="99%"><tr><td class="BBquote"><br>&nbsp;&nbsp;&nbsp; public class KnownTypeProvider : IKnownTypeProvider<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #region Implementation of IKnownTypeProvider<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public IEnumerable&lt;Type&gt; AddKnownTypes()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new&#091;&#093;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(SerializedExpression),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typeof(List&lt;SerializedExpression&gt;),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #endregion<br>&nbsp;&nbsp;&nbsp; }<br></td></tr></table><br><span style="font-size:10px"><br /><br />Edited by smi-mark - 11-Aug-2013 at 12:28pm</span>]]>
   </description>
   <pubDate>Sun, 11 Aug 2013 12:26:57 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16710#16710</guid>
  </item> 
  <item>
   <title>Save a Query : That&amp;#039;s basically what I was...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16708#16708</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=452" rel="nofollow">ken.nelson</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 09-Aug-2013 at 7:55am<br /><br /><div>That's basically what I was attempting in my 3rd option, but I can't seem to get it to work. I'm getting an exception when I try to send the SerializedExpression to our server.</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>var p1 = PredicateBuilder.Make&lt;Requirement&gt;(i =&gt; i.FTN.Contains("345"));</div><div>var q = ASTEM.Requirements.Where(p1);</div><div>var expr = SerializedExpression.ToSerializedExpression(q.Expression);</div><div><br></div><div>// At this point we send expr to our web service method.</div><div></pre></td></tr></table></div><div><br></div><div><em></div><div>'Type 'IdeaBlade.Core.TypeWrapper' with data contract name 'TypeWrapper:http://ideablade.com/Core' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.</div><div></em></div><div><br></div><div>So to eliminate our call to our web service method being the issue, I tried:</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>var p1 = PredicateBuilder.Make&lt;Requirement&gt;(i =&gt; i.FTN.Contains("345"));</div><div>var q = ASTEM.Requirements.Where(p1);</div><div>var expr = SerializedExpression.ToSerializedExpression(q.Expression);</div><div><br></div><div>var serializer = new DataContractSerializer(expr.GetType());</div><div><br></div><div>byte&#091;&#093; data = null;</div><div>using (var stream = new MemoryStream())</div><div>{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; serializer.WriteObject(stream, expr);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; stream.Seek(0, SeekOrigin.Begin);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; data = stream.GetBuffer();</div><div>}</div><div></pre></td></tr></table></div><div><br></div><div>Which results in the same exception when calling serializer.WriteObject().</div><div><br></div><div>If I add TypeWrapper as a known type by doing the following, I receive the same exception for a different type:</div><div><br></div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>var knownTypes = new List&lt;Type&gt;()</div><div>{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; typeof(IdeaBlade.Core.TypeWrapper)</div><div>}:</div><div><br></div><div>var serializer = new DataContractSerializer(expr.GetType(), knownTypes);</div><div></pre></td></tr></table></div><div><br></div><div><em></div><div>Type 'IdeaBlade.EntityModel.EntityQueryProxy`1&#091;&#091;AST.ObjectModel.Requirement, AST.ObjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dba36b71950587e5&#093;&#093;' with data contract name 'EntityQueryProxyOfRequirement_PBxM0UCr:http://ideablade.com/EntityModel' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.</div><div></em></div><div><br></div><div>And if I add expr.GetType() to the known types list, it doesn't appear to help at all. I continue to get that same exception.</div><div><br></div><div><div><table width="99%"><tr><td><pre class="BBcode"></div><div>var knownTypes = new List&lt;Type&gt;()</div><div>{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; typeof(IdeaBlade.Core.TypeWrapper),</div><div>&nbsp; &nbsp; &nbsp; &nbsp; expr.GetType()</div><div>}:</div><div><br></div><div>var serializer = new DataContractSerializer(expr.GetType(), knownTypes);</div><div></pre></td></tr></table></div><div><br></div><div><em></div><div>Type 'IdeaBlade.EntityModel.EntityQueryProxy`1&#091;&#091;AST.ObjectModel.Requirement, AST.ObjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=dba36b71950587e5&#093;&#093;' with data contract name 'EntityQueryProxyOfRequirement_PBxM0UCr:http://ideablade.com/EntityModel' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.</div><div></em></div></div><div><br></div>]]>
   </description>
   <pubDate>Fri, 09 Aug 2013 07:55:01 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16708#16708</guid>
  </item> 
  <item>
   <title>Save a Query : Hi Ken,It won&amp;#039;t be a simple...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16704#16704</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=892" rel="nofollow">sbelini</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 08-Aug-2013 at 3:31pm<br /><br />Hi Ken,<div><br></div><div>It won't be a simple task.</div><div><br></div><div>As far as sending the query to the server, you could do it by following the steps at&nbsp;<span style="line-height: 1.4;">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12343#12343.</span></div><div><br></div><div>Once in the server, you could handle the SerializableExpression as you see fit.</div><div><br></div>]]>
   </description>
   <pubDate>Thu, 08 Aug 2013 15:31:18 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16704#16704</guid>
  </item> 
  <item>
   <title>Save a Query : Is there any way to save an EntityQuery?...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16702#16702</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=452" rel="nofollow">ken.nelson</a><br /><strong>Subject:</strong> 4265<br /><strong>Posted:</strong> 08-Aug-2013 at 7:19am<br /><br />Is there any way to save an EntityQuery? Not the results of a query, but the query itself or even a representation of the query (PredicateDescription, SQL), such that an EntityQuery could be constructed at a later time? We're using Silverlight.<div><br></div><div>Our users have requested an ability to define filters (build a dynamic query), save those filters, and have those filters be loaded back into the application. The user can then select a previously defined filter and have it execute to get the current results.&nbsp;<span style="line-height: 1.4;">We can't simply save the results of the query because the results of these queries may change over time.</span></div><div><span style="line-height: 1.4;"><br></span></div><div><span style="line-height: 1.4;">Things I've tried:</span></div><div><ul><li><span style="line-height: 1.4;">My first thought was to convert the LINQ-based EntityQuery to SQL, store the SQL string, and later create a PassthruEsqlQuery from the stored SQL, but I can't seem to find a way to convert the EntityQuery to SQL on the Silverlight client.</span></li><li><span style="line-height: 1.4;">I considered just serializing the EntityQuery or a PredicateDescription as XML using a DataContractSerializer but neither are marked with &#091;DataContract&#093;.</span></li><li><span style="line-height: 1.4;">I noticed that EntityQuery has an Expression property, and I tried converting it to the "for internal use" SerializedExpression which is marked with a &#091;DataContract&#093; but I'm obviously doing something wrong there because I keep getting exceptions while attempting to serialize.</span></li><li><span style="line-height: 1.4;">My latest attempt was to try serializing as binary using a memory stream, but the BinaryFormatter doesn't seem to exist in the Silverlight libraries.</span></li></ul><div>I feel like there has to be an easy way to accomplish this but&nbsp;<span style="line-height: 1.4;">I'm running out of ideas.</span></div></div><div><br></div><div>Thanks,</div><div>Ken</div>]]>
   </description>
   <pubDate>Thu, 08 Aug 2013 07:19:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=4265&amp;PID=16702#16702</guid>
  </item> 
 </channel>
</rss>