score:6

Accepted answer

as @domysee mentioned you cannot call any c# function within a linq query. only entitifunctions that's why expressions have been built for. to be used inside linq queries

        public expression<func<emailaflawmmessage, bool>> getselectxpr(string filter, string value)
        {
            if (filter == "attachments")
                return e => e.attachments == value;
            else if (filter == "flagged")
                return e => e.flagged == value;
            else
                return e => e.seen == value;
        }

usage.

var selectxpr = getgetselectxpr(filter,value);
    var emailmessage = db.emailaflawmmessage.where(selectxpr).orderbydescending(a=>a.msg_date).select(a=> 
     new {
     a.subject,
     a.msg_date
   })

score:5

unfortunately it isn't possible to use methods inside a where of an iqueryable, because linq to sql cannot know how to translate your method into sql.

you have to inline your method into the where to make it work.
something like that:

private iqueryable searchfiltercondition(string filter,string value)
{
    var filterparam = filterparameter(filter); //evaluate filterparameter outside of the query
    var emailmessage = from a in db.emailaflawmmessage
                       where (filterparam == value)
                       orderby a.msg_date descending
                       select new
                       {
                           a.subject,
                           a.msg_date,         
                       };
    return emailmessage;
}

Related Query

More Query from same tag