예제 #1
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);
        }
예제 #2
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);
        }