Convert GUID to string Entity Framework

At the risk of asking a duplicate question, I cannot seem to get this to work. There are many examples of what I want to do but the syntax isnt quite the same and nothing has worked. I am teaching myself Linq. This query gets a list of ids from SQL server. Without the "ToString()" it says "cant convert GUID to string[]". Please advise and thanks in advance.

    public string[] GetAllRoleIDs(string param)
    {           
        using (DBEntities de = new DBEntities())
        {
            string[] roleset = (from p in de.MySQLView
                         where p.anotherfield == param
                                select p.RoleID.ToString()).Distinct().ToArray();

            return roleset;
        }            
    }
Jon Skeet
people
quotationmark

You want AsEnumerable() to force the ToString() call to be evaluated locally rather than as part of the EF query. For example:

using (DBEntities de = new DBEntities())
{
    string[] roleset = de.MySQLView
                         .Where(p => p.anotherfield == param)
                         .Select(p => p.RoleID)
                         .Distinct()
                         .AsEnumerable()
                         .Select(guid => guid.ToString())
                         .ToArray();
    return roleset;
}

(I've converted it from a query expression to use dot notation just because mixing and matching between the two is cumbersome, and you've only got a where and a select. You can use a query expression if you like, of course.)

people

See more on this question at Stackoverflow