MemberPredicate for Custom Member

Posts   
 
    
Posts: 93
Joined: 13-Feb-2008
# Posted on: 31-Mar-2008 17:17:27   

The member predicate system doesn't support custom members. Here is what I have done to support custom properties that return an entity or a collection of entities. Basically alter a MemberPredicate method to look for the member with reflection if its not in the generated dictionary...

from: SD.LLBLGen.Pro.ORMSupportClasses.MemberPredicate


protected override bool InterpretPredicate(IEntityCore entity)
        {
                   //...

            object memberData = null;
            if (!allMemberData.TryGetValue(_memberName, out memberData))
            {
                //if not in dictionary then inspect with reflection
                PropertyInfo pi = entity.GetType().GetProperty(_memberName);

                if (pi != null)
                {
                    memberData = pi.GetValue(entity, null);
                }
                else
                {
                    // member not found
                    throw new ORMInterpretationException(string.Format("The member '{0}' isn't found in the entity '{1}'", _memberName, entity.LLBLGenProEntityName));
                }
            }
                    //...

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 31-Mar-2008 19:05:05   

Thanks for sharing!