Beispiel #1
0
        private bool IsDerivedCollection(Type CollectionType)
        {
            var itemType = TypesUtil.GetGenericArgumentForBaseType(CollectionType, typeof(IEnumerable <>));

            //if entityType is a non-entity, it will not have any mapping.
            return(typeTranslationUtil.GetMapping <IModelEntityMapping>(itemType) is IDerivedModelEntityMapping);
        }
Beispiel #2
0
        public Func <object, object> GetTranslatedMemberValue(Type entityType, Type tableEntityType, string memberName
                                                              , TypeTranslationUtil typeTranslationUtil)
        {
            var member = tableEntityType.GetProperty(memberName);

            if (member != null)
            {
                return entity =>
                       {
                           var result = member.GetValue(entity);
                           return result;
                       }
            }
            ;
            else
            {
                var baseTableEntityProp = tableEntityType.GetProperty((typeTranslationUtil.GetMapping <IModelEntityMapping>(entityType) as IDerivedModelEntityMapping).BaseClassProperty);

                var basePropertyGetter = GetTranslatedMemberValue(entityType.BaseType, baseTableEntityProp.PropertyType, memberName, typeTranslationUtil);
                return(entity =>
                {
                    var result = baseTableEntityProp.GetValue(basePropertyGetter(entity));
                    return result;
                });
            }
        }
Beispiel #3
0
        public static SimpleType GetMember(SimpleType source, MemberExpression memberExp, MemberExpression translatedMemberExp, TypeTranslationUtil typeTranslationUtil)
        {
            SimpleType result;

            if (source != null)
            {
                result = source.GetMemberType(memberExp);
                if (result != null)
                {
                    return(result);
                }
            }

            var includes           = (source != null) ? source.GetMemberIncludes(memberExp) : new List <IncludeDirective>();
            var memberIsCollection = TypesUtil.IsNonPrimitiveCollection(memberExp.Type);

            var classMapping = typeTranslationUtil.GetMapping <IModelEntityMapping>(memberExp.Member.DeclaringType);

            if (memberIsCollection && classMapping != null)
            {
                //Getting the many-to-many maps for the declaringType
                var manyToManyRelationship = classMapping.GetManyToManyRelationships()
                                             .FirstOrDefault(m => ((MemberExpression)m.RelatedEntitySelector.Body).Member.Name == memberExp.Member.Name);
                if (manyToManyRelationship != null)
                {
                    var otherEndSelector           = manyToManyRelationship.RelatedEntitySelectorFromMap.Body as MemberExpression;
                    var param                      = Expression.Parameter(typeTranslationUtil.GetTranslatedType(manyToManyRelationship.MapType), "x");
                    var translatedOtherEndSelector = typeTranslationUtil.GetMemberExpression
                                                         (manyToManyRelationship.MapType, otherEndSelector.Member.Name, param);
                    var map = new ManyToManyMapType(manyToManyRelationship.MapType, param.Type,
                                                    TypesUtil.GetGenericArgumentForBaseType(memberExp.Type, typeof(ICollection <>)),
                                                    manyToManyRelationship, translatedOtherEndSelector.Member)
                    {
                        Includes = includes
                    };
                    return(new SimpleType(memberExp.Type, translatedMemberExp.Type)
                    {
                        NonPrimitiveEnumerableItemType = map
                    });
                }
            }

            result = new SimpleType(memberExp.Type, translatedMemberExp.Type);
            if (memberIsCollection)
            {
                var itemType           = TypesUtil.GetGenericArgumentForBaseType(memberExp.Type, typeof(IEnumerable <>));
                var translatedItemType = TypesUtil.GetGenericArgumentForBaseType(translatedMemberExp.Type, typeof(IEnumerable <>));
                var innerType          = new SimpleType(itemType, translatedItemType)
                {
                    Includes = includes
                };
                result.NonPrimitiveEnumerableItemType = innerType;
            }
            else
            {
                result.Includes = includes;
            }
            return(result);
        }
Beispiel #4
0
        public static bool IsEquivalent(this IEntity source, IEntity target)
        {
            if (source == null || target == null || source.GetType() != target.GetType())
            {
                return(false);
            }

            var typeTranslationUtil = new TypeTranslationUtil();
            var identityProperties  = typeTranslationUtil.GetMapping <IEntityMapping>(source.GetType()).GetIdentityFields().Cast <LambdaExpression>()
                                      .Select(l => (l.Body as MemberExpression).Member as PropertyInfo).ToList();

            return(identityProperties.All(p => p.GetValue(source).Equals(p.GetValue(target))));
        }