Q:

Dynamic OrderBy() using property not in DB throws exception

I have the following models:
public class User
{
    public string UserId { get; set; }
    public string UserName { get; set; }
    public List<Membership> Membership { get; set; }
    public bool IsRegistered
    {
        get { return ! String. IsNullOrEmpty(UserName); }
    }
}

public class Membership
{
    public string MembershipId { get; set; }
    public User User { get; set; }
}

In my repository for the Membership entity, I'm attempting to order my collection by doing the following where entries is an IQueryable<Membership> and orderBy is a LamdaExpression equal to { x => x.User. IsRegistered }:
ordered = Queryable. OrderBy(ordered, orderBy);

When I attempt this, I get the following error:

The specified type member 'IsRegistered' is not supported in LINQ to
  Entities.  Only initializers, entity members, and entity navigation
  properties are supported. 

How can I order my collection by a property that is not in the database? 
Thanks in advance. 

A:

Since IsRegistered is a client side function, then you need to do the ordering using LINQ over objects.   You can convert your LINQ over SQL to LINQ over objects by causing it to get enumerated.   Then once it's a LINQ over objects, you can then order it using LINQ over obect's OrderBy.   A common method of doing that is by calling ToList, like:
ordered = Queryable. ToList().OrderBy(ordered, orderBy);

If you want to do the ordering on the database, then you need to convert your clientside code to one that is compatible to SQL, like:
ordered = Queryable. OrderBy(ordered, (x=>x. User. UserName!=null && x.User. UserName!=''));

