<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Fluent</title>
        <link>http://geekswithblogs.net/EltonStoneman/category/10643.aspx</link>
        <description>Fluent</description>
        <language>en-GB</language>
        <copyright>EltonStoneman</copyright>
        <managingEditor>elton.stoneman@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>FluentHtmlTextWriter</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/09/10/fluenthtmltextwriter.aspx</link>
            <description>&lt;p style="TEXT-ALIGN: center"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;[Source: &lt;a href="http://geekswithblogs.net/EltonStoneman"&gt;http://geekswithblogs.net/EltonStoneman&lt;/a&gt;] &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Keeping up the&lt;font style="BACKGROUND-COLOR: #ffffff"&gt; &lt;/font&gt;&lt;a href="http://geekswithblogs.net/EltonStoneman/Admin/EditPosts.aspx?catid=10643"&gt;fluent &lt;/a&gt;work, I've put together a fluent interface which wraps the framework &lt;strong&gt;HtmlTextWriter&lt;/strong&gt;. For ASP.NET MVC, this makes generating HTML in extension methods to &lt;strong&gt;HtmlHelper&lt;/strong&gt; safer than &lt;em&gt;string.Format()&lt;/em&gt; and more readable than &lt;strong&gt;HtmlTextWriter&lt;/strong&gt;: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Image(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; imageRelativeUrl, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; altText) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;FluentHtmlTextWriter&lt;/span&gt;.Begin() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WriteTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Img) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Src, GetImageUrl(imageRelativeUrl)) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Alt, altText) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.End(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;The equivalent using &lt;strong&gt;HtmlTextWriter&lt;/strong&gt; is: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Image(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;HtmlHelper&lt;/span&gt; helper, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; imageRelativeUrl, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; altText) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;{ &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;StringBuilder&lt;/span&gt; htmlBuilder = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;StringBuilder&lt;/span&gt;(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriter&lt;/span&gt; writer = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;HtmlTextWriter&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;StringWriter&lt;/span&gt;(htmlBuilder)); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.AddAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Src, GetImageUrl(imageRelativeUrl)); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.AddAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Alt, altText); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.RenderBeginTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Img); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.RenderEndTag(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.Flush(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt; htmlBuilder.ToString(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;}&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;Unlike the framework writer, you're not constrained to specify attributes in any particular order, and tags which aren't nested can be written with a single &lt;em&gt;WriteTag()&lt;/em&gt;, rather than &lt;em&gt;BeginTag()&lt;/em&gt; and &lt;em&gt;EndTag()&lt;/em&gt; calls. The writer copes with multi-level tag hierarchies - this sample builds a &lt;a href="http://users.tpg.com.au/j_birch/plugins/superfish/"&gt;Superfish&lt;/a&gt; CSS menu: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;FluentHtmlTextWriter&lt;/span&gt; writer = &lt;span style="COLOR: #2b91af"&gt;FluentHtmlTextWriter&lt;/span&gt;.Begin(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;writer.BeginTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Ul) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Id, &lt;span style="COLOR: #a31515"&gt;"menu.Name"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Class, &lt;span style="COLOR: #a31515"&gt;"sf-menu sf-vertical"&lt;/span&gt;); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.BeginTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Li) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.BeginTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.A) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Class, &lt;span style="COLOR: #a31515"&gt;"sf-with-ul"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Href, &lt;span style="COLOR: #a31515"&gt;"#"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithValue(&lt;span style="COLOR: #a31515"&gt;"Link 1"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WriteTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Span) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Class, &lt;span style="COLOR: #a31515"&gt;"sf-sub-indicator"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithValue(&lt;span style="COLOR: #a31515"&gt;"&amp;amp;#187;"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.EndTag() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.EndTag() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.EndTag(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; html = writer.End(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="COLOR: #a31515"&gt;"&amp;lt;ul id=\"menu.Name\" class=\"sf-menu sf-vertical\"&amp;gt;\r\n\t&amp;lt;li&amp;gt;&amp;lt;a class=\"sf-with-ul\" href=\"#\"&amp;gt;Link 1&amp;lt;span class=\"sf-sub-indicator\"&amp;gt;&amp;amp;#187;&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;\r\n&amp;lt;/ul&amp;gt;"&lt;/span&gt;, &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;html);&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;HtmlTextWriter&lt;/strong&gt; equivalent is unthinkable. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://ondevelopment.blogspot.com/"&gt;Patrik Hägne&lt;/a&gt; has an alternative &lt;a href="http://ondevelopment.blogspot.com/2009/01/htmltextwriter-fluent-interface.html"&gt;fluent HtmlTextWriter&lt;/a&gt; implementation, which is nicely put together, but I wanted slightly different functionality. Firstly I wanted to get the HTML string from the writer directly, without needing to instantiate a &lt;strong&gt;StringBuilder&lt;/strong&gt; and &lt;strong&gt;StringWriter&lt;/strong&gt;. Secondly I wanted minimal new code – Patrik uses a separate class to manage writing attributes, and has specific functions for known tag types. Thirdly, I didn't really like Patrik's syntax, with the need to specify the tag type when you write an end tag – and when tags aren't nested, I wanted to write them in a single unit: &lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; html = &lt;span style="COLOR: #2b91af"&gt;FluentHtmlTextWriter&lt;/span&gt;.Begin() &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WriteTag(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterTag&lt;/span&gt;.Span) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithAttribute(&lt;span style="COLOR: #2b91af"&gt;HtmlTextWriterAttribute&lt;/span&gt;.Id, &lt;span style="COLOR: #a31515"&gt;"id_span"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.WithValue(&lt;span style="COLOR: #a31515"&gt;"contents_span"&lt;/span&gt;) &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;.End(); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="FONT-SIZE: 9pt; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(&lt;span style="COLOR: #a31515"&gt;"&amp;lt;span id=\"id_span\"&amp;gt;contents_span&amp;lt;/span&amp;gt;"&lt;/span&gt;, html);&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;My version is on MSDN Code Gallery here: &lt;a href="http://code.msdn.microsoft.com/FluentHtmlTextWriter"&gt;FluentHtmlTextWriter&lt;/a&gt;. It works by building up a list of actions when you start writing a tag, and flushing them in the correct order to an internal &lt;strong&gt;HtmlTextWriter&lt;/strong&gt; when you start writing the next tag. When you call &lt;em&gt;End()&lt;/em&gt; it flushes the internal writer and outputs its contents. An alternative constructor lets you write directly to an output stream, in which case you can &lt;em&gt;Flush()&lt;/em&gt; the writer and don't need to call &lt;em&gt;End()&lt;/em&gt;. &lt;/p&gt;
&lt;p&gt;The current implementation only deals with basic tag, attribute and style functionality, and doesn't include optional HTML encoding overloads. It's only 75 lines of code, and extending it should be trivial. &lt;/p&gt;
&lt;p&gt;There is a negligible performance hit in using &lt;strong&gt;FluentHtmlTextWriter&lt;/strong&gt; – running the image tag generation code above 20,000 times on my dev machine, the fluent version takes between 0.01and 0.02 seconds longer than the framework version (on average 0.07 seconds compared to 0.05). &lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134758"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134758" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/134758.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/09/10/fluenthtmltextwriter.aspx</guid>
            <pubDate>Fri, 11 Sep 2009 00:32:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/134758.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/09/10/fluenthtmltextwriter.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/134758.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Fluent DAL Mapping</title>
            <link>http://geekswithblogs.net/EltonStoneman/archive/2009/09/08/fluent-dal-mapping.aspx</link>
            <description>&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;If you spend some time using &lt;a href="http://fluentnhibernate.org/"&gt;Fluent NHibernate&lt;/a&gt;, you’ll want to use its neat style of mapping for all data access, even when you’re working against traditional DALs. I’ve put a sample up on MSDN Code Gallery for this scenario, using a fluent style of mapping between domain objects and data readers populated by stored procedure calls.&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;The interface is very similar to FNH, with a mapping class used for each domain entity – this is a simple mapping class:&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt"&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;PostCodeMap&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;DataReaderMap&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;PostCode&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;{&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; PostCodeMap()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        Map(x =&amp;gt; x.InwardCode, &lt;span style="COLOR: #a31515"&gt;"PS_IN"&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        Map(x =&amp;gt; x.OutwardCode, &lt;span style="COLOR: #a31515"&gt;"PS_OUT"&lt;/span&gt;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    }&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;The string constants define the column names expected in the data reader, and the base class takes care of running the map. For more complex entities, &lt;strong&gt;DataReaderMap&lt;/strong&gt; also includes mapping via a conversion function:&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    Map&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt;&amp;gt;(x =&amp;gt; x.Activated, &lt;span style="COLOR: #a31515"&gt;"AccountActivated"&lt;/span&gt;, &lt;span style="COLOR: #2b91af"&gt;Legacy&lt;/span&gt;.FromBoolean);&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;- where the mapping specifies to and from types, and a delegate to invoke for the conversion (in this case, a method which converts a legacy string representation of a boolean – Y/N – to a bool).&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;For composite objects, the base map includes referencing, for cases where the child entity is loaded from the same data reader as the parent entity:&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    References(x =&amp;gt; x.Address, &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AddressMap&lt;/span&gt;());&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;Where the child entity is read from a separate data reader, then the composition needs to be done outside of the map in a repository or an assembler component. The &lt;strong&gt;Load&lt;/strong&gt; class isolates calling the stored procedure, so you get a fluent interface for populating domain objects, and collections of objects:&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; GetUser(&lt;span style="COLOR: #2b91af"&gt;Guid&lt;/span&gt; userId)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        &lt;span style="COLOR: green"&gt;//populate basic details:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        &lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; user = &lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load&amp;lt;&lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt;&amp;gt;().With&amp;lt;&lt;span style="COLOR: #2b91af"&gt;UserMap&lt;/span&gt;&amp;gt;()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;                            .From&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GetUser&lt;/span&gt;&amp;gt;(i =&amp;gt; i.UserId = userId,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;                                           x =&amp;gt; x.Execute());&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        &lt;span style="COLOR: green"&gt;//add accounts:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        user.Accounts = &lt;span style="COLOR: #2b91af"&gt;Fluently&lt;/span&gt;.Load&amp;lt;&lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Account&lt;/span&gt;&amp;gt;&amp;gt;().With&amp;lt;&lt;span style="COLOR: #2b91af"&gt;AccountMap&lt;/span&gt;&amp;gt;()&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;                                .From&amp;lt;&lt;span style="COLOR: #2b91af"&gt;GetUserAccounts&lt;/span&gt;&amp;gt;(i =&amp;gt; i.UserId = userId,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;                                                       x =&amp;gt; x.Execute());&lt;/span&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="FONT-SIZE: 10pt"&gt;        &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; user;&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;&lt;span style="FONT-SIZE: 10pt"&gt;    }&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;The &lt;em&gt;From()&lt;/em&gt; call specifies the type of stored procedure, an action to populate the object, in this case setting up the &lt;em&gt;UserId&lt;/em&gt; parameter, and a function to call which returns a data reader, in this case &lt;em&gt;Execute().&lt;/em&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0cm 0cm 10pt"&gt;The full sample is on the gallery here: &lt;a href="http://code.msdn.microsoft.com/FluentDALMapping"&gt;Fluent DAL Mapping&lt;/a&gt; . It’s a simple task to extend the sample to load datasets, or to populate update procedure calls from entities. If your database is sufficiently conventional this could be extended to provide FNH-style auto-mapping, reflecting over entities and using conventions to map properties to column names.&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134544"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=134544" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/EltonStoneman/aggbug/134544.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>EltonStoneman</dc:creator>
            <guid>http://geekswithblogs.net/EltonStoneman/archive/2009/09/08/fluent-dal-mapping.aspx</guid>
            <pubDate>Tue, 08 Sep 2009 07:32:20 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/EltonStoneman/comments/134544.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/EltonStoneman/archive/2009/09/08/fluent-dal-mapping.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/EltonStoneman/comments/commentRss/134544.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>