LinqQuery provided filter Func

Posts   
 
    
Jazz
User
Posts: 63
Joined: 12-Aug-2005
# Posted on: 08-Apr-2010 16:30:34   

Hi there,

I wrote a general query to filter for different columns of the same Entity. Here's what I came up with:


public static ContactingEntity GetContactingEntity(Func<ContactingEntity, bool> filter) {
            using (var adapter = new DataAccessAdapter()) {
                var metaData = new LinqMetaData(adapter);

                var q = (from t in metaData.Contacting
                                 where filter(t)
                                 select t).WithPath(_ContactingPrefetch);

                foreach (var te in q) {
                    return te;
                }
            }
            return null;
        }

And two methods that actually provide the filtering:


        public static ContactingEntity GetContactingEntityByLogin(string login) {
            return GetContactingEntity(o => o.Login.Equals(login));
        }

        public static ContactingEntity GetContactingEntity(int contactingId) {
            return GetContactingEntity(o => o.Id.Equals(contactingId));
        }

I'm getting an exception:


SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryConstructionException: The binary expression '(Invoke(value(System.Func`2[dgoContentPortal.EntityClasses.ContactingEntity,System.Boolean]),[507]) = True)' can't be converted to a predicate expression.

Is it possible to provide filtering that way? Do I have to use Function Mapping?

Regards, André

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 08-Apr-2010 20:54:00   

Yes - that is what function mapping is designed for. LLBLGen is trying to convert your filter to one of it's own predicate expression but does not know how to convert it.

Matt