title: Converting guid to string with entity framework
body: <p>I'm trying to pass a GUID as a string over web services, however I've hit a bump in the road. The GUID is stored in SQL Server as a <code>UNIQUEIDENTIFIER</code> and EF pulls it as a GUID. What I would want to do is in my query do this:</p>
  
  <pre><code>var query = myEntities.Foo.Where(q =&gt; q.Id== Id)
                  .Select(bar =&gt;
                          new Bar()
                              { BString = bar.GUID }
                          );
  </code></pre>
  
  <p>Now, C# throws a build error that you cannot convert <code>System.Guid</code> to <code>string</code>, so I'd think that you could do this:</p>
  
  <pre><code>{ BString = bar.GUID.ToString() }
  </code></pre>
  
  <p>or even</p>
  
  <pre><code>{ BString = Convert.ToString(bar.GUID) }
  </code></pre>
  
  <p>But both end with runtime exception:</p>
  
  <blockquote>
    <p>There was an exception, it was System.NotSupportedException: LINQ to
    Entities does not recognize the method 'System.String
    ToString(System.Object)' method, and this method cannot be translated
    into a store expression.</p>
  </blockquote>
  
  <p>So I gather that in both cases, it's not able to figure out a T-SQL equivalent of going from <code>UniqueIdentifier</code> to <code>varchar</code>.</p>
  
  <p>Is there a way around this besides retrieving the object, then iterating over my return set copying each object to a new object and converting guid->string at that point?</p>
  
  <p>Thanks.</p>