<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Select Max Value With LINQ To SQL</title>
	<atom:link href="http://www.thereforesystems.com/select-max-value-with-linq-to-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/</link>
	<description>a learning effort by Deepak Kapoor</description>
	<lastBuildDate>Thu, 09 Feb 2012 13:29:34 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: manesti</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-199275</link>
		<dc:creator>manesti</dc:creator>
		<pubDate>Mon, 05 Dec 2011 08:53:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-199275</guid>
		<description>Thank you very much</description>
		<content:encoded><![CDATA[<p>Thank you very much</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KCuncle</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-160811</link>
		<dc:creator>KCuncle</dc:creator>
		<pubDate>Mon, 12 Sep 2011 07:44:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-160811</guid>
		<description>thk for sample</description>
		<content:encoded><![CDATA[<p>thk for sample</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepak</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-137210</link>
		<dc:creator>Deepak</dc:creator>
		<pubDate>Thu, 21 Jul 2011 00:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-137210</guid>
		<description>Most welcome el Khatib.</description>
		<content:encoded><![CDATA[<p>Most welcome el Khatib.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: el Khatib</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-136946</link>
		<dc:creator>el Khatib</dc:creator>
		<pubDate>Wed, 20 Jul 2011 13:36:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-136946</guid>
		<description>Thanks you so much :)</description>
		<content:encoded><![CDATA[<p>Thanks you so much :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Filipe Colaço</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-51207</link>
		<dc:creator>Filipe Colaço</dc:creator>
		<pubDate>Sat, 27 Nov 2010 01:09:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-51207</guid>
		<description>Sorry:

var q = (from data in db.Tickets.Where(p =&gt; (p.DataInsercao).Year == System.DateTime.Now.Year).OrderByDescending(p =&gt; p.Ticket)
                         select new {data.Ticket }).Take(1);                

                foreach (var v in q)
                {
                      LabelTicket.Text = (v.Ticket).ToString();
                }</description>
		<content:encoded><![CDATA[<p>Sorry:</p>
<p>var q = (from data in db.Tickets.Where(p =&gt; (p.DataInsercao).Year == System.DateTime.Now.Year).OrderByDescending(p =&gt; p.Ticket)<br />
                         select new {data.Ticket }).Take(1);                </p>
<p>                foreach (var v in q)<br />
                {<br />
                      LabelTicket.Text = (v.Ticket).ToString();<br />
                }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Filipe Colaço</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-51206</link>
		<dc:creator>Filipe Colaço</dc:creator>
		<pubDate>Sat, 27 Nov 2010 01:04:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-51206</guid>
		<description>Solution:

var q = (from data in db.Tickets.Where(p =&gt; (p.DataInsercao).Year == System.DateTime.Now.Year).OrderByDescending(p =&gt; p.Ticket)
                         select data).Take(1);                

                foreach (var v in q)
                {
                    //Response.Write(v.Ticket.ToString());
                    LabelTicket.Text = v.Ticket.ToString();

                }</description>
		<content:encoded><![CDATA[<p>Solution:</p>
<p>var q = (from data in db.Tickets.Where(p =&gt; (p.DataInsercao).Year == System.DateTime.Now.Year).OrderByDescending(p =&gt; p.Ticket)<br />
                         select data).Take(1);                </p>
<p>                foreach (var v in q)<br />
                {<br />
                    //Response.Write(v.Ticket.ToString());<br />
                    LabelTicket.Text = v.Ticket.ToString();</p>
<p>                }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohammad Elsheimy</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-44862</link>
		<dc:creator>Mohammad Elsheimy</dc:creator>
		<pubDate>Sat, 30 Oct 2010 21:14:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-44862</guid>
		<description>Nice tip, I used not to use LINQ in my code wherever I can, but I think that there&#039;re times when you MUST use it. Selecting max values for me without T-SQL means to iterate through all the rows to get the max value. :(

Thanks for your help! :)</description>
		<content:encoded><![CDATA[<p>Nice tip, I used not to use LINQ in my code wherever I can, but I think that there&#8217;re times when you MUST use it. Selecting max values for me without T-SQL means to iterate through all the rows to get the max value. :(</p>
<p>Thanks for your help! :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Deepak</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-37993</link>
		<dc:creator>Deepak</dc:creator>
		<pubDate>Thu, 23 Sep 2010 01:14:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-37993</guid>
		<description>James,

Max is supported in LINQ To SQL queries. I ran the query you posted on a sample database and it worked.</description>
		<content:encoded><![CDATA[<p>James,</p>
<p>Max is supported in LINQ To SQL queries. I ran the query you posted on a sample database and it worked.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: james</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-37983</link>
		<dc:creator>james</dc:creator>
		<pubDate>Wed, 22 Sep 2010 19:59:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-37983</guid>
		<description>With the above exception, the workaround was as follows:

var query = _context.Execute(new Uri(string.Format(&quot;{0}/PrintChecks?$orderby=PrintCheckID desc&amp;$top=1&amp;$select=PrintCheckID&quot;, _context.BaseUri), UriKind.RelativeOrAbsolute));

                var printCheck = query.FirstOrDefault();</description>
		<content:encoded><![CDATA[<p>With the above exception, the workaround was as follows:</p>
<p>var query = _context.Execute(new Uri(string.Format(&#8220;{0}/PrintChecks?$orderby=PrintCheckID desc&amp;$top=1&amp;$select=PrintCheckID&#8221;, _context.BaseUri), UriKind.RelativeOrAbsolute));</p>
<p>                var printCheck = query.FirstOrDefault();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: james</title>
		<link>http://www.thereforesystems.com/select-max-value-with-linq-to-sql/comment-page-1/#comment-37979</link>
		<dc:creator>james</dc:creator>
		<pubDate>Wed, 22 Sep 2010 19:38:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.thereforesystems.com/select-max-value-with-linq-to-sql/#comment-37979</guid>
		<description>Exception raised:
The method &#039;Max&#039; is not supported.

       public int GetLastPrintCheckID()
        {
            try
            {
                var printCheck = (from o in _context.PrintChecks
                                  select o.PrintCheckID).Max();
                return printCheck;
            }
            catch (Exception exx)
            {
                return 0;
            }
        }</description>
		<content:encoded><![CDATA[<p>Exception raised:<br />
The method &#8216;Max&#8217; is not supported.</p>
<p>       public int GetLastPrintCheckID()<br />
        {<br />
            try<br />
            {<br />
                var printCheck = (from o in _context.PrintChecks<br />
                                  select o.PrintCheckID).Max();<br />
                return printCheck;<br />
            }<br />
            catch (Exception exx)<br />
            {<br />
                return 0;<br />
            }<br />
        }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

