<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.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>Performance Tip: Return Only Necessary Columns Using LINQ</title><link>http://weblogs.asp.net/jgaylord/archive/2008/06/10/performance-tip-return-only-necessary-columns-using-linq.aspx</link><description>I was running into an issue where one of my webmethods was taking a large amount of time to return a small set (5-10 objects). I was using LINQ to SQL. I noticed that the LINQ to SQL query was returning all of the rows. After looking into the table a</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>re: Performance Tip: Return Only Necessary Columns Using LINQ</title><link>http://weblogs.asp.net/jgaylord/archive/2008/06/10/performance-tip-return-only-necessary-columns-using-linq.aspx#6272095</link><pubDate>Fri, 13 Jun 2008 14:00:47 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6272095</guid><dc:creator>Cecil</dc:creator><author>Cecil</author><description>&lt;p&gt;True that works. Also if you're using a 3-tier approach, then returning anonymous types in your CRUD methods&lt;/p&gt;
&lt;p&gt; is a lil different. Some I'd have to create an altered type to hold the small column set.&lt;/p&gt;
&lt;p&gt; So For instance if I have a query that returns IEnumerable&amp;lt;Student&amp;gt;, I'd create a StudentAlt&lt;/p&gt;
&lt;p&gt; class and return IEnumerable&amp;lt;StudentAlt&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class FSEHS_STUDENT_MIN {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string NSUID { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string FIRST_NAME { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public string LAST_NAME { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public override string ToString() {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return &amp;quot;NSUID: &amp;quot; + NSUID + &amp;quot;\nFirst Name :&amp;quot; + FIRST_NAME;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;partial class FSEHS_STUDENT {&lt;/p&gt;
&lt;p&gt; &amp;nbsp;public static IEnumerable&amp;lt;STUDENTALT&amp;gt; select() {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; SchoolDataContext db = new DataContext(); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return from m in db.FSEHS_STUDENTs.Take(200) &amp;nbsp;select new FSEHS_STUDENT_MIN{ FIRST_NAME=m.FIRST_NAME}; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public static IEnumerable&amp;lt;STUDENT&amp;gt; select() {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SchoolDataContext db = new SchoolDataContext();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return from m in db.FSEHS_STUDENTs.Take(200) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select m;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6272095" width="1" height="1"&gt;</description></item><item><title>re: Performance Tip: Return Only Necessary Columns Using LINQ</title><link>http://weblogs.asp.net/jgaylord/archive/2008/06/10/performance-tip-return-only-necessary-columns-using-linq.aspx#6268961</link><pubDate>Wed, 11 Jun 2008 20:20:04 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6268961</guid><dc:creator>ZamesCurran</dc:creator><author>ZamesCurran</author><description>&lt;p&gt;I'm told just creating an anonymous struct for the fields, instead of return the native LINQ object (even if it includes all of the columns) will speed things up, as the native object is dragging around a lot of extra weight (mainly there in case you update the object)&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6268961" width="1" height="1"&gt;</description></item><item><title>Performance Tip: Return Only Necessary Columns Using LINQ</title><link>http://weblogs.asp.net/jgaylord/archive/2008/06/10/performance-tip-return-only-necessary-columns-using-linq.aspx#6267753</link><pubDate>Wed, 11 Jun 2008 07:21:54 GMT</pubDate><guid isPermaLink="false">c06e2b9d-981a-45b4-a55f-ab0d8bbfdc1c:6267753</guid><dc:creator>Performance Tip: Return Only Necessary Columns Using LINQ</dc:creator><author>Performance Tip: Return Only Necessary Columns Using LINQ</author><description>&lt;p&gt;Pingback from &amp;nbsp;Performance Tip: Return Only Necessary Columns Using LINQ&lt;/p&gt;
&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6267753" width="1" height="1"&gt;</description></item></channel></rss>