

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Plastic/Blog &#187; Add new tag</title>
	<atom:link href="http://blog.codiceplastico.com/index.php/tag/add-new-tag/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codiceplastico.com</link>
	<description>Code Elegance</description>
	<lastBuildDate>Sat, 28 Aug 2010 10:27:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>DTO and LINQ</title>
		<link>http://blog.codiceplastico.com/index.php/2007/11/13/dto-and-linq/</link>
		<comments>http://blog.codiceplastico.com/index.php/2007/11/13/dto-and-linq/#comments</comments>
		<pubDate>Tue, 13 Nov 2007 05:00:13 +0000</pubDate>
		<dc:creator>Emanuele DelBono</dc:creator>
				<category><![CDATA[Emanuele DelBono]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://blogema.wordpress.com/2007/11/13/dto-and-linq/</guid>
		<description><![CDATA[I would like to say a little thing about DTO. With the advent of LINQ most of the things that I wrote in my old post are not necessary anymore. With the new C# 3.0 is not necessary to build a custom new class for every DTO, you can use the capability called Anonymous Type [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to say a little thing about DTO.</p>
<p>With the advent of LINQ most of the things that I wrote in my old post are not necessary anymore. With the new C# 3.0 is not necessary to build a custom new class for every DTO, you can use the capability called Anonymous Type to create new types on the fly.</p>
<p>Take as example the (usual) case of Customer Address objects, and as the lasts post we want to show on a table the list of Customers with their FullAddress.</p>
<p>With LINQ is not necessary to write a new CustomerDTO class, you can use the following code to obtain the same result:</p>
<div class="wlWriterSmartContent" style="display:inline;float:none;width:470px;margin:0;padding:0;">
<div><span style="color: #0000ff;">public</span><span style="color: #000000;"> IEnumerable GetCustomers() { IList</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">Customer</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> customers </span><span style="color: #000000;">=</span><span style="color: #000000;"> LoadCustomerFromDB(); IEnumerable list </span><span style="color: #000000;">=</span><span style="color: #000000;"> from c </span><span style="color: #0000ff;">in</span><span style="color: #000000;"> customers select </span><span style="color: #0000ff;">new</span><span style="color: #000000;"> { Name</span><span style="color: #000000;">=</span><span style="color: #000000;">c.Name, FullAddress</span><span style="color: #000000;">=</span><span style="color: #000000;">(c.Address.Street </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #800000;"> </span><span style="color: #800000;">&#8220;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> c.Address.City) }; </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> list; } </span></div>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></p>
</div>
<p>This snippet create a new Anonymous Type with two properties (Name and FullAddress) without the need to create a custom class.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codiceplastico.com/index.php/2007/11/13/dto-and-linq/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
