<?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 : Serializing SortSelector</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Serializing SortSelector</description>
  <pubDate>Wed, 13 May 2026 14:12:39 -700</pubDate>
  <lastBuildDate>Tue, 03 Jan 2012 13:58:45 -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=3187</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>Serializing SortSelector :   We do have special logic to...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12357#12357</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3187<br /><strong>Posted:</strong> 03-Jan-2012 at 1:58pm<br /><br />We do have special logic to "constantize" local variables when passed in a query, but this is provided in one of the internal expression visitors and not available to applications.&nbsp; So, your best option is probably to pass the parameter like you're doing.<div>&nbsp;</div><div>We do have an open feature request to "provide an easier way to pass a query to an RPC method", but since you're only the second person to ask about it, it hasn't gotten a lot of attention.&nbsp;&nbsp; I'll add your requirements to the request, and we'll see what we can do!</div>]]>
   </description>
   <pubDate>Tue, 03 Jan 2012 13:58:45 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12357#12357</guid>
  </item> 
  <item>
   <title>Serializing SortSelector : This may just be an issue with...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12356#12356</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> 3187<br /><strong>Posted:</strong> 03-Jan-2012 at 1:26pm<br /><br />This may just be an issue with the SerializedExpression, but I have an expression like so:<br><br>var year = 2011;<br><br>Expression&lt;Func&lt;Statement, bool&gt;&gt; filter = s =&gt; s.Year == year;<br><br>This fails because it uses the variable as a reference, and not value, so when it's serialized it fails on the server. This works fine on a query, as I imagine it simply replaces it with the value. <br><br>For now I'm having to pass the parameter to the server separately.<br><br>Are there any plans for a future version to make some of this easier? If not, can I add a feature request to do so?<br><br>Thanks!<br>]]>
   </description>
   <pubDate>Tue, 03 Jan 2012 13:26:07 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12356#12356</guid>
  </item> 
  <item>
   <title>Serializing SortSelector :   Haha. This is some pretty...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12350#12350</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> 3187<br /><strong>Posted:</strong> 30-Dec-2011 at 2:47pm<br /><br />Haha. This is some pretty code, but it works.<br><br>Client:<br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">var</span>&nbsp;sortExpressions&nbsp;=&nbsp;<span style="color:blue;">new</span>&nbsp;<span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">SerializedExpression</span>&gt;(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">if</span>&nbsp;(sortSelector&nbsp;<span style="color:blue;">is</span>&nbsp;<span style="color:#2b91af;">SortSelector</span>)&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;&nbsp;&nbsp;sortExpressions.Add(<span style="color:#2b91af;">SerializedExpression</span>.ToSerializedExpression(((<span style="color:#2b91af;">SortSelector</span>)sortSelector).ToLambdaExpression()));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">else</span>&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;&nbsp;&nbsp;sortExpressions.AddRange(((<span style="color:#2b91af;">CompositeSortSelector</span>)sortSelector).Selectors.Select(s&nbsp;=&gt;&nbsp;<span style="color:#2b91af;">SerializedExpression</span>.ToSerializedExpression(s.ToLambdaExpression())));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>Server:<br></pre><br><pre style="font-family:C&#111;nsolas;font-size:13;color:black;:white;"><span style="color:blue;">var</span>&nbsp;expressions&nbsp;=&nbsp;sortExpressions.Select(s&nbsp;=&gt;&nbsp;s.ToExpression()&nbsp;<span style="color:blue;">as</span>&nbsp;<span style="color:#2b91af;">Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;<span style="color:#2b91af;">Dealer</span>,&nbsp;<span style="color:blue;">string</span>&gt;&gt;);baseQuery&nbsp;=&nbsp;baseQuery.OrderBy(expressions.First());baseQuery&nbsp;=&nbsp;expressions.Skip(1)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.Aggregate(baseQuery,&nbsp;(current,&nbsp;sortExpression)&nbsp;=&gt;&nbsp;current.ThenBy(sortExpression));<br><br>Thanks for the help :)<br><br>P.S. I just took a look at the SerializedExpression code. That must have been fun to write and debug!!!<br></pre><br><span style="font-size:10px"><br /><br />Edited by smi-mark - 30-Dec-2011 at 2:53pm</span>]]>
   </description>
   <pubDate>Fri, 30 Dec 2011 14:47:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12350#12350</guid>
  </item> 
  <item>
   <title>Serializing SortSelector :   Hmm, nothing is ever easy...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12349#12349</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3187<br /><strong>Posted:</strong> 30-Dec-2011 at 12:25pm<br /><br />Hmm, nothing is ever easy :).&nbsp; I don't see any way to generate a single expression from the CompositeSortSelector, but it&nbsp;has a Selectors collection property which you can iterate through to first generate a LambdaExpression for each selector, and then a SerializedExpression for each, and then pass these along to the server method.&nbsp;&nbsp;For example:&nbsp;<div>&nbsp;</div><div>&nbsp; var sortexps = cs.Selectors.Select(s =&gt; s.ToLambdaExpression()).Select(l =&gt; SerializedExpression.ToSerializedExpression(l)).ToList();</div>]]>
   </description>
   <pubDate>Fri, 30 Dec 2011 12:25:56 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12349#12349</guid>
  </item> 
  <item>
   <title>Serializing SortSelector : Hi Kim,Thanks for the response...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12348#12348</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> 3187<br /><strong>Posted:</strong> 30-Dec-2011 at 11:43am<br /><br />Hi Kim,<br><br>Thanks for the response - this looks like it will work great. In my repository, my search method takes an ISortSelector but ToLambdaExpression is a method on the class not an extension. When I change to use SortSelector rather than ISortSelector, I run into errors where I am using CompositeSortSelector.<br><br>What would you recommend I do? <br><br>Thanks!<br>]]>
   </description>
   <pubDate>Fri, 30 Dec 2011 11:43:37 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12348#12348</guid>
  </item> 
  <item>
   <title>Serializing SortSelector :   We don&amp;#039;t make this easy,...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12347#12347</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=11" rel="nofollow">kimj</a><br /><strong>Subject:</strong> 3187<br /><strong>Posted:</strong> 30-Dec-2011 at 11:16am<br /><br />We don't make this easy, which is by accident not design.&nbsp; <div>&nbsp;</div><div>Internally, DevForce creates&nbsp;an EntityQuerySurrogate when sending a query to the server.&nbsp; This is essentially a wrapper over the query expression, along with some means of rehydrating the query.&nbsp; Unfortunately, this also has an internal constructor.&nbsp; </div><div>&nbsp;</div><div>You can, though, do some of what the surrogate does yourself using the IdeaBlade.Linq.SerializedExpression class.&nbsp; You need to add this type as a known type on both client and server.&nbsp; You can create a SerializedExpression for a whole query, or a portion of it, as you want here.&nbsp; It's a bit tricky to use.</div><div>&nbsp;</div><div>To build SerializedExpressions for your query parts you can do something like this:&nbsp;</div><div>&nbsp;</div><div>var p1 = PredicateBuilder.Make&lt;Product&gt;(p =&gt; p.Discontinued == false);<br>var&nbsp;exp1&nbsp;= SerializedExpression.ToSerializedExpression(p1);</div><div>&nbsp;</div><div>var ss = new SortSelector(typeof(Product), "ProductName");<br>var exp2 = SerializedExpression.ToSerializedExpression(ss.ToLambdaExpression());</div><div>&nbsp;</div><div>You'd then pass the SerializedExpressions to the server method, which could build a query as follows:</div><div>&nbsp;</div><div>var p1 = args&#091;0&#093; as SerializedExpression;&nbsp; // where<br>var p2 = args&#091;1&#093; as SerializedExpression;&nbsp;&nbsp; // sort</div><div>&nbsp;</div><div>var exp1 = p1.ToExpression() as Expression&lt;Func&lt;Product, bool&gt;&gt;;<br>var exp2 = p2.ToExpression() as Expression&lt;Func&lt;Product, string&gt;&gt;;</div><div>var query = em.GetQuery&lt;Product&gt;().Where(exp1).OrderBy(exp1);</div><div>&nbsp;</div><div>As you can see, it's a bit messy rehydrating the expresions.&nbsp; If you don't know the entity type, you can pass that with the IdeaBlade.Core.TypeWrapper class, which is specifically designed for serializing type information.&nbsp; </div><div>&nbsp;</div><div>You could instead build up the dynamic query on your client and pass the query expression to your server method.&nbsp; It would look something like this:</div><div>&nbsp;</div><div>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);</div><div>var exp = SerializedExpression.ToSerializedExpression(query.Expression);</div><div>&nbsp;</div><div>On the server you'd build up the query like this:</div><div>&nbsp;</div><div>var p1 = args&#091;0&#093; as SerializedExpression;&nbsp; // query<br>var exp = p1.ToExpression();<br>var baseQuery = (IQueryable)TypeFns.ConstructGenericInstance(typeof(EntityQuery&lt;&gt;), typeof(Product));<br>var query = (EntityQuery)TypeFns.ConstructGenericInstance(typeof(EntityQuery&lt;&gt;),<br>&nbsp; new Type&#091;&#093; { baseQuery.ElementType }, exp, baseQuery);</div><div>&nbsp;</div><div>&nbsp;</div>]]>
   </description>
   <pubDate>Fri, 30 Dec 2011 11:16:24 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12347#12347</guid>
  </item> 
  <item>
   <title>Serializing SortSelector : I have a server method that takes...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12343#12343</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> 3187<br /><strong>Posted:</strong> 29-Dec-2011 at 2:35pm<br /><br />I have a server method that takes a sort selector and an Expression&lt;Func&lt;EntityType,bool&gt;&gt; and I've noticed that both of these cannot be serialized. What is the correct way to do this? Simply adding it to known type does not work.<br><br>]]>
   </description>
   <pubDate>Thu, 29 Dec 2011 14:35:29 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3187&amp;PID=12343#12343</guid>
  </item> 
 </channel>
</rss>