<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>C# on Coding out loud</title><link>https://amoerie.com/tags/c%23/</link><description>Recent content in C# on Coding out loud</description><generator>Hugo -- 0.155.2</generator><language>en-us</language><lastBuildDate>Sat, 09 Mar 2013 14:06:08 +0000</lastBuildDate><atom:link href="https://amoerie.com/tags/c%23/index.xml" rel="self" type="application/rss+xml"/><item><title>Replacing method calls with expressions at runtime with Linqkit and the Entity Framework</title><link>https://amoerie.com/posts/2013-03-09-replacing-method-calls-linqkit/</link><pubDate>Sat, 09 Mar 2013 14:06:08 +0000</pubDate><guid>https://amoerie.com/posts/2013-03-09-replacing-method-calls-linqkit/</guid><description>&lt;blockquote&gt;
&lt;p&gt;LINQ to Entities does not recognize the method &amp;lsquo;&amp;hellip;&amp;rsquo; method, and this method cannot be translated into a store expression.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Does this sound familiar to you? It&amp;rsquo;s a common issue that many developers face, as evidenced by the astronomical amount of questions about it on &lt;a href="http://stackoverflow.com/search?q=LINQ+to+Entities+does+not+recognize+the+method"&gt;stackoverflow.com&lt;/a&gt;&lt;/p&gt;
&lt;h2 id="the-problem"&gt;The problem&lt;/h2&gt;
&lt;p&gt;To understand why this happens, you must first realize that Linq To Entities - the thing that produces the SQL statements for you - never really executes your C# code. So when you write:&lt;/p&gt;</description></item><item><title>Applying the builder pattern to the .Net MVC TagBuilder</title><link>https://amoerie.com/posts/2013-02-25-builder-pattern-tagbuilder/</link><pubDate>Mon, 25 Feb 2013 20:51:07 +0000</pubDate><guid>https://amoerie.com/posts/2013-02-25-builder-pattern-tagbuilder/</guid><description>&lt;p&gt;Sometimes I&amp;rsquo;m a nitpicker. Actually I&amp;rsquo;m a nitpicker 24/7, but I can&amp;rsquo;t really say that on a blog, can I?&lt;/p&gt;
&lt;p&gt;So today&amp;rsquo;s nitpicking is about C#&amp;rsquo;s TagBuilder. This class allows you to build html without writing a single &amp;lsquo;&amp;lt;&amp;rsquo; or &amp;lsquo;&amp;gt;&amp;rsquo;. Using this class usually boils down to something like this:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-csharp" data-lang="csharp"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// this will create &amp;lt;button&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;var&lt;/span&gt; input = &lt;span style="color:#66d9ef"&gt;new&lt;/span&gt; TagBuilder(&lt;span style="color:#e6db74"&gt;&amp;#34;button&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// Set some attributes&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;input.Attributes.Add(&lt;span style="color:#e6db74"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;property.name&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;input.Attributes.Add(&lt;span style="color:#e6db74"&gt;&amp;#34;id&amp;#34;&lt;/span&gt;, &lt;span style="color:#e6db74"&gt;&amp;#34;property_id&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// some classes for markup&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;input.AddCssClass(&lt;span style="color:#e6db74"&gt;&amp;#34;btn btn-primary&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;// equivalent to jQuery&amp;#39;s $(&amp;#34;property_id&amp;#34;).text(&amp;#34;Click me!&amp;#34;);&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;input.InnerHtml = &lt;span style="color:#e6db74"&gt;&amp;#34;Click me!&amp;#34;&lt;/span&gt;;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;However, wouldn&amp;rsquo;t it be nicer if we could say:&lt;/p&gt;</description></item></channel></rss>