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; }); } }
public QueryAnalysisContext(TypeTranslationUtil typeTranslationUtil, Dictionary<ParameterExpression, ParameterReplacement> paramDictionary) { this.TypeTranslationUtil = typeTranslationUtil; this.ParameterDictionary = new Dictionary<ParameterExpression, ParameterReplacement>(); if (paramDictionary != null) foreach (var item in paramDictionary) this.ParameterDictionary.Add(item.Key, item.Value); }
//Create Where Clause using Identity Fields & source values static Expression <Func <T, bool> > GetIdentityWhereClause <T>(T source) { var parameter = Expression.Parameter(typeof(T), "x"); var whereCondition = new TypeTranslationUtil().GetMapping <IEntityMapping>(typeof(T)) .GetIdentityFields().OfType <LambdaExpression>().Select(x => ((MemberExpression)x.Body).Member) .Select(member => Expression.Equal(Expression.MakeMemberAccess(parameter, member), Expression.Constant(member.GetValue(source)))) .Aggregate((accumulate, equal) => Expression.And(accumulate, equal)); return(Expression.Lambda <Func <T, bool> >(whereCondition, parameter)); }
public QueryAnalysisContext(TypeTranslationUtil typeTranslationUtil, Dictionary <ParameterExpression, ParameterReplacement> paramDictionary) { this.TypeTranslationUtil = typeTranslationUtil; this.ParameterDictionary = new Dictionary <ParameterExpression, ParameterReplacement>(); if (paramDictionary != null) { foreach (var item in paramDictionary) { this.ParameterDictionary.Add(item.Key, item.Value); } } }
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)))); }
public POCOReference(object entity, bool isLoaded) { this.IsLoaded = isLoaded; if (entity != null) { var identities = new TypeTranslationUtil().GetMapping <IModelEntityMapping>(entity.GetType()).GetIdentityFields(); var keyMembers = new List <POCOKeyMember>(); foreach (LambdaExpression exp in identities) { var prop = ExpressionUtil.GetProperty(exp, entity.GetType()); keyMembers.Add(new POCOKeyMember(prop.Name, prop.GetValue(entity, null))); } this.POCOKeyMembers = keyMembers.ToArray(); } }
public CompilableQueryAnalyzer(LambdaExpression originalExpression, TypeTranslationUtil typeTranslationUtil) { this.originalExpression = originalExpression; this.typeTranslationUtil = typeTranslationUtil; Visit(originalExpression); }
public QueryAnalysisContext(TypeTranslationUtil typeTranslationUtil) : this(typeTranslationUtil, new Dictionary<ParameterExpression, ParameterReplacement>()) { }
public virtual Func <object, object> GetTranslatedMemberValue(MemberInfo memInfo, TypeTranslationUtil typeTranslationUtil) { return(GetTranslatedMemberValue(this.Type, this.TranslatedType, memInfo.Name, typeTranslationUtil)); }
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); }
public override Func <object, object> GetTranslatedMemberValue(MemberInfo memInfo, TypeTranslationUtil typeTranslationUtil) { return(base.GetTranslatedMemberValue(MemberMap[memInfo], typeTranslationUtil)); }
public QueryAnalysisContext(TypeTranslationUtil typeTranslationUtil) : this(typeTranslationUtil, new Dictionary <ParameterExpression, ParameterReplacement>()) { }
public ProjectionModifier(Expression currentExpression, SimpleType queryableType, TypeTranslationUtil typeTranslationUtil) { this.queryableType = queryableType; this.currentExpression = currentExpression; this.typeTranslationUtil = typeTranslationUtil; }