title: Entity Framework 6 and AsNonUnicode method
body: <p>I'm using entity framework 6 and have exception "LINQ to Entities does not recognize the method 'System.String AsNonUnicode(System.String)' method". Here is what I do.</p>
  
  <p>I have table Customers with email column defined as varchar(254) (non-Unicode).</p>
  
  <p>In my mapping I have following line:</p>
  
  <pre><code>Property(t =&gt; t.Email).IsUnicode(false);
  </code></pre>
  
  <p>When I put my query like this:</p>
  
  <pre><code>var q = context.Customers.Where(t =&gt; t.Email == "a@gmail.com").Select(t =&gt; t.FirstName);
  </code></pre>
  
  <p>everything is fine, the constant is non-Unicode. However, if I use this code:</p>
  
  <pre><code>string email = "a@gmail.com";
  var q = context.Customers.Where(t =&gt; t.Email == email);
  </code></pre>
  
  <p>the variable being generated is Unicode one, which results in not using index.</p>
  
  <p>So, I tried using EntityFunctions.AsNonUnicode extension, which seemed to be designed for this:</p>
  
  <pre><code>string email = "a@gmail.com";
  var q = context.Customers.Where(t =&gt; t.Email == EntityFunctions.AsNonUnicode(email));
  </code></pre>
  
  <p>However, I got an exception LINQ to Entities does not recognize the method 'System.String AsNonUnicode(System.String)' method exception when trying to actually query data.</p>
  
  <p>What am I doing wrong?</p>