Order by in dynamic Linq expression http://forums.asp.net/t/1788929.aspx/1?Order+by+in+dynamic+Linq+expression+Mon, 07 May 2012 04:36:38 -040017889294915170http://forums.asp.net/p/1788929/4915170.aspx/1?Order+by+in+dynamic+Linq+expression+Order by in dynamic Linq expression <p>How can i use orderby to a colum Rank ( which i s created dynamicaaly based on some conditions)&nbsp; instaed of LastUpdated</p> <pre class="prettyprint">var rrrr = (from item in dbContext.Blogs orderby item.LastUpdated descending select new { item, Rank = item.Title.Contains(&quot;title&quot;) ? 4 : item.Author.Contains(&quot;author&quot;) ? 3 : item.Tag.Contains(&quot;tagname&quot;) ? 2 : 0 });</pre> <p><br> Is it possible to use OrderBy on Rank (cynamically created column ) ? If yes how can can i do that else what are the other ways to do achieve this</p> 2012-04-04T06:26:26-04:004915198http://forums.asp.net/p/1788929/4915198.aspx/1?Re+Order+by+in+dynamic+Linq+expression+Re: Order by in dynamic Linq expression <p>make a .ToList and then make an OrderBy in memory</p> <p>or</p> <p>make a calculated column in database( preferred)</p> 2012-04-04T06:44:02-04:004915232http://forums.asp.net/p/1788929/4915232.aspx/1?Re+Order+by+in+dynamic+Linq+expression+Re: Order by in dynamic Linq expression <pre class="prettyprint">var rrrr = (from item in dbContext.Blogs orderby item.LastUpdated descending select new { item, Rank = item.Title.Contains(&quot;title&quot;) ? 4 : item.Author.Contains(&quot;author&quot;) ? 3 : item.Tag.Contains(&quot;tagname&quot;) ? 2 : 0 }).OrderByDescending(i=&gt;i.Rank);</pre> <p></p> <p>Is working for me.. i am not sure about the perfomance of this querry in a working environment (extract from thousands of records ) and sort in memory .. Is it a good way?</p> 2012-04-04T07:03:06-04:004918794http://forums.asp.net/p/1788929/4918794.aspx/1?Re+Order+by+in+dynamic+Linq+expression+Re: Order by in dynamic Linq expression <p></p> <blockquote><span class="icon-blockquote"></span> <h4>mMATHAI</h4> Is it a good way?</blockquote> <p></p> <p>I think sobecause your Rank doesn't belong to your table and it's only a type of an anoymous property of the anoymous class</p> <p>Reguards</p> 2012-04-06T01:30:34-04:004968150http://forums.asp.net/p/1788929/4968150.aspx/1?Re+Order+by+in+dynamic+Linq+expression+Re: Order by in dynamic Linq expression <p>I am not sure about the perfomance, but it works fine for me on a table with thousands of rows..</p> 2012-05-07T04:36:38-04:00