score:2

Accepted answer

the answer to this question is a bit more complicated than it looks. in order to let linq execute c# code you need to make the function an expression so the in and output will be interperted not as code but as some sort of a meaning. the solution looks like this:

 private expression<func<tpeople, bool>> getdefaultdomainaccount<tpeople>(func<domainaccount, bool> f) where tpeople : person
        {
            return (a) => f(a.domainaccounts.firstordefault(d => d.domainaccounttype == domainaccounttype.standarduser));
        }

now the code can be called uppon like this:

    public iqueryable<tpeople> getpeoplebyusername<tpeople>(string username) where tpeople : person
    {
        getpeople<tpeople>().where(getdefaultdomainaccount<tpeople>(d => d.username == username));
        return people;
    }

instead of this:

        public iqueryable<tpeople> getpeoplebyusername<tpeople>(string username) where tpeople : person
    {
        username = username.toupper();
        var people = getpeople<tpeople>()
            .where(a => a.domainaccounts.firstordefault(d => d.domainaccounttype == domainaccounttype.standarduser).username.toupper().contains(username));

        return people;
    }

Related Query

More Query from same tag