Beispiel #1
0
        private static void Setup_SelectByKeyValueArray(SpecialLinqCommand command)
        {
            var member         = command.Key.ExpandedKeyMembers[0].Member;
            var listType       = typeof(IList <>).MakeGenericType(member.DataType);
            var listPrm        = Expression.Parameter(listType, "@list");
            var entType        = command.Key.Entity.EntityType;
            var pred           = ExpressionMaker.MakeListContainsPredicate(member, listPrm);
            var entSet         = member.Entity.EntitySetConstant;
            var entSetFiltered = ExpressionMaker.MakeCallWhere(entSet, pred);
            var entSetOrdered  = ExpressionMaker.AddOrderBy(entSetFiltered, command.OrderBy);

            command.Lambda = Expression.Lambda(entSetOrdered, listPrm);
        }
Beispiel #2
0
        private static void Setup_SelectByValueArrayManyToMany(SpecialLinqCommand command)
        {
            var listInfo        = command.ListInfoManyToMany;
            var fkMember        = listInfo.ParentRefMember.ReferenceInfo.FromKey.ExpandedKeyMembers[0].Member;
            var listType        = typeof(IList <>).MakeGenericType(fkMember.DataType);
            var listPrm         = Expression.Parameter(listType, "@list");
            var entType         = listInfo.LinkEntity.EntityType;
            var wherePred       = ExpressionMaker.MakeListContainsPredicate(fkMember, listPrm);
            var linkEntSet      = fkMember.Entity.EntitySetConstant;
            var entSetFiltered  = ExpressionMaker.MakeCallWhere(linkEntSet, wherePred);
            var targetRefMember = listInfo.OtherEntityRefMember;
            var entSetOrdered   = AddOrderByManyToMany(entSetFiltered, listInfo.LinkEntity, listInfo.OtherEntityRefMember, command.OrderBy);
            var newTupleLambda  = ExpressionMaker.MakeNewLinkTupleLambda(listInfo.OtherEntityRefMember);
            var selectTuple     = ExpressionMaker.MakeCallSelect(entSetOrdered, newTupleLambda);

            command.Lambda = Expression.Lambda(selectTuple, listPrm);
        }
Beispiel #3
0
        // Setup methods

        private static void Setup_SelectByKey(SpecialLinqCommand command)
        {
            var key      = command.Key;
            var lockType = command.LockType;
            var orderBy  = command.OrderBy;

            var entType = key.Entity.EntityType;
            var prms    = key.ExpandedKeyMembers.Select(m => Expression.Parameter(m.Member.DataType, "@" + m.Member.MemberName)).ToArray();
            var pred    = ExpressionMaker.MakeKeyPredicate(key, prms);
            var entSet  = (lockType == LockType.None) ? key.Entity.EntitySetConstant
                                               : ExpressionMaker.MakeEntitySetConstant(entType, lockType);
            var entSetFiltered = ExpressionMaker.MakeCallWhere(entSet, pred);
            var entSetOrdered  = ExpressionMaker.AddOrderBy(entSetFiltered, command.OrderBy);
            var lambdaExpr     = Expression.Lambda(entSetOrdered, prms);

            command.Lambda = lambdaExpr;
        }
Beispiel #4
0
        private static void Setup_SelectManyToMany(SpecialLinqCommand command)
        {
            /* Building smth like that:
             * var tuplesQuery = session.EntitySet<IBookAuthor>().Where(ba => ba.Book.Id == csBookId)
             *  .OrderBy(ba => ba.Author.LastName)
             *  .Select(ba => new Data.Linq.LinkTuple() { LinkEntity = ba, TargetEntity = ba.Author });
             *
             * the query returns list of LinkTuple objects <LinkEnt, TargetEnt>
             *
             */
            var listInfo        = command.ListInfoManyToMany;
            var keyParentRef    = listInfo.ParentRefMember.ReferenceInfo.FromKey;
            var prms            = keyParentRef.ExpandedKeyMembers.Select(m => Expression.Parameter(m.Member.DataType, "@" + m.Member.MemberName)).ToArray();
            var wherePred       = ExpressionMaker.MakeKeyPredicate(keyParentRef, prms);
            var linkEntSet      = listInfo.LinkEntity.EntitySetConstant;
            var entSetFiltered  = ExpressionMaker.MakeCallWhere(linkEntSet, wherePred);
            var targetRefMember = listInfo.OtherEntityRefMember;
            var entSetOrdered   = AddOrderByManyToMany(entSetFiltered, listInfo.LinkEntity, listInfo.OtherEntityRefMember, command.OrderBy);
            var newTupleLambda  = ExpressionMaker.MakeNewLinkTupleLambda(listInfo.OtherEntityRefMember);
            var selectTuple     = ExpressionMaker.MakeCallSelect(entSetOrdered, newTupleLambda);

            command.Lambda = Expression.Lambda(selectTuple, prms);
        }