Пример #1
0
        protected virtual bool HasCorrespondingTableEntityType(Type type)
        {
            if (TypesUtil.IsPrimitiveDataType(type))
            {
                return(true);
            }

            return(IsEntity(type));
        }
Пример #2
0
        public static IncludeDirective GetIncludeInCollectionDirective(MemberExpression collectionMemberExp, LambdaExpression collectionFieldSelector)
        {
            var parameter          = ExpressionUtil.GetParameterExpression(collectionMemberExp);
            var collectionItemType = TypesUtil.GetGenericArgumentForBaseType(collectionMemberExp.Type, typeof(ICollection <>));
            var delegateType       = typeof(Func <,>).MakeGenericType(parameter.Type, typeof(IEnumerable <>).MakeGenericType(collectionItemType));
            var collectionSelector = Expression.Lambda(delegateType, collectionMemberExp, parameter);

            var includeType = typeof(IncludeInCollectionDirective <,>).MakeGenericType(parameter.Type, collectionItemType);

            return(Activator.CreateInstance(includeType, collectionSelector, collectionFieldSelector) as IncludeDirective);
        }
Пример #3
0
 public virtual Type GetTranslatedType(Type t)
 {
     if (TypesUtil.IsCompilerGeneratedAnonymousType(t))
     {
         var typeArgs = t.GetGenericArguments().Select(x => GetTranslatedType(x)).ToArray();
         return(t.GetGenericTypeDefinition().MakeGenericType(typeArgs));
     }
     else
     {
         if (HasCorrespondingTableEntityType(t))
         {
             return(GetTableEntityType(t));
         }
         else
         {
             return(null);
         }
     }
 }
Пример #4
0
 public bool IsEntityCollection(Type t)
 {
     //?Todo: Also check if the generic type of the collection is IEntity
     if (t.IsGenericType && (typeof(ICollection <>).IsAssignableFrom(t.GetGenericTypeDefinition())))
     {
         if (IsEntity(TypesUtil.GetGenericArgumentForBaseType(t, typeof(ICollection <>))))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Пример #5
0
        public Func <object, IIntermediateEntityContainer> MakeBackingContainerGetter(Type entityType, MemberInfo property)
        {
            if (entityType.GetProperty(property.Name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) != null)
            {
                var intermediateEntityType = GetMapping <IEntityMapping>(entityType).IntermediateEntityType;
                var member = TypesUtil.GetIntermediateContainer(intermediateEntityType, property.Name);
                return(tableEntity => member.GetValue(tableEntity) as IIntermediateEntityContainer);
            }
            var derivedMapping = GetMapping <IDerivedModelEntityMapping>(entityType);

            if (derivedMapping != null)
            {
                var baseProperty         = derivedMapping.IntermediateEntityType.GetProperty("_base");
                var baseTypeMemberGetter = MakeBackingContainerGetter(entityType.BaseType, property);
                return(tableEntity => baseTypeMemberGetter(baseProperty.GetValue(tableEntity)));
            }
            else
            {
                throw new InvalidOperationException("Member does not exist in the inheritance chain.");
            }
        }