<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Data Access and ObjectDataSource Control</title><link>http://forums.asp.net/23.aspx</link><description>Questions and discussions related to using ADO.NET for data access, and the ObjectDataSource control. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=9&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Dynamic Sort in Linq Statement</title><link>http://forums.asp.net/thread/2754824.aspx</link><pubDate>Wed, 19 Nov 2008 11:22:48 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2754824</guid><dc:creator>DeepakKapoor.NET</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2754824.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=2754824</wfw:commentRss><description>Hi Levi,&lt;p&gt;I have tried to answer your question at &lt;a href="http://www.onedotnetway.com/dynamic-sort-with-linq-to-sql/"&gt;http://www.onedotnetway.com/dynamic-sort-with-linq-to-sql/&lt;/a&gt; &lt;/p&gt;&lt;p&gt;I hope this helps.&lt;/p&gt;&lt;p&gt;Regards,&lt;/p&gt;</description></item><item><title>Dynamic Sort in Linq Statement</title><link>http://forums.asp.net/thread/2753778.aspx</link><pubDate>Tue, 18 Nov 2008 23:10:09 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2753778</guid><dc:creator>lpage</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2753778.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=23&amp;PostID=2753778</wfw:commentRss><description>&lt;p&gt;Does anyone have any examples of how to include a dynamic sort field into a linq statement? There are lots of examples online on how to sort on a supplied field name, but the work is done after grabbing the data from the database. &lt;strong&gt;I actually want to grab the data from the database already sorted&lt;/strong&gt;. Here are some quick details:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;1) The field name is supplied by a grid, so compile time I don&amp;#39;t know what the field name will be.&amp;nbsp;This example addresses that, but it does the processing after grabbing the data: &lt;a href="http://www.onedotnetway.com/dynamic-sort-with-linq/"&gt;http://www.onedotnetway.com/dynamic-sort-with-linq/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;2) I have a bunch of data, so i have a linq statement that grabs only the first 10 records... On top of that I need to inject the supplied field name so I can sort or group by it. The field is only determined during run time.&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;var&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; query = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;from&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; v &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; db.myTable &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;where&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; v.SiteID == siteID &amp;amp;&amp;amp; v.VisitDate &amp;gt;= dataDate &amp;amp;&amp;amp; v.VisitDate &amp;lt;= dataDate.AddDays(1)&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;select&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;VisitListDataRowOld&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;visitornumber=v.VisitorNumber,&lt;/p&gt;visitdate= &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;DateUtil&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.GetDateString(v.VisitDate),&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;};&lt;/p&gt;
&lt;p&gt;data.visits = query.Skip(startRowIndex).Take(maximumRows).ToList();&lt;/p&gt;
&lt;p&gt;data.recordcount = query.Count();&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;How can I pull this data from the database already sorted?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thanks!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Levi&lt;/strong&gt;&lt;/p&gt;&lt;/font&gt;</description></item></channel></rss>