コード例 #1
0
        /// <summary>
        /// Creates the tuple prototype with specified <paramref name="primaryKey"/>.
        /// </summary>
        /// <param name="primaryKey">The primary key to use.</param>
        /// <param name="typeIdValue">Identifier of <see cref="Entity"/> type.</param>
        /// <returns>
        /// The <see cref="TuplePrototype"/> with "injected" <paramref name="primaryKey"/>.
        /// </returns>
        public Tuple CreateEntityTuple(Tuple primaryKey, int typeIdValue)
        {
            var result = primaryKeyInjector.Apply(TupleTransformType.Tuple, primaryKey, TuplePrototype);

            if (typeIdField != null)
            {
                result.SetValue(typeIdField.MappingInfo.Offset, typeIdValue);
            }
            return(result);
        }
コード例 #2
0
        public void MainTest()
        {
            Xtensive.Tuples.Tuple source    = Tuple.Create(1);
            MapTransform          transform = new MapTransform(true, TupleDescriptor.Create <byte, int, string>(), new[] { -1, 0 });

            Xtensive.Tuples.Tuple result = transform.Apply(TupleTransformType.TransformedTuple, source);
            Assert.AreEqual(TupleFieldState.Default, result.GetFieldState(0));
            Assert.AreEqual(TupleFieldState.Available, result.GetFieldState(1));
            Assert.AreEqual(TupleFieldState.Default, result.GetFieldState(2));
        }
コード例 #3
0
        private static Expression <Func <IEnumerable <Tuple> > > RemapRawProviderSource(Expression <Func <IEnumerable <Tuple> > > source, MapTransform mappingTransform)
        {
            var selectMethodInfo = typeof(Enumerable)
                                   .GetMethods()
                                   .Single(methodInfo => methodInfo.Name == "Select" &&
                                           methodInfo.GetParameters()[1].ParameterType.GetGenericTypeDefinition() == typeof(Func <,>))
                                   .MakeGenericMethod(typeof(Tuple), typeof(Tuple));

            Func <Tuple, Tuple> selector = tuple => mappingTransform.Apply(TupleTransformType.Auto, tuple);
            var newExpression            = Expression.Call(selectMethodInfo, source.Body, Expression.Constant(selector));

            return((Expression <Func <IEnumerable <Tuple> > >)FastExpression.Lambda(newExpression));
        }
コード例 #4
0
        /// <summary>
        /// Cuts out <paramref name="segment"/> from <paramref name="tuple"/> <see cref="Tuple"/>.
        /// </summary>
        /// <param name="tuple">The <see cref="Tuple"/> to get segment from.</param>
        /// <param name="segment">The <see cref="Segment{T}"/> to cut off.</param>
        /// <returns></returns>
        public static Tuple GetSegment(this Tuple tuple, Segment <int> segment)
        {
            var map = new int[segment.Length];

            for (int i = 0; i < segment.Length; i++)
            {
                map[i] = segment.Offset + i;
            }

            var types      = new ArraySegment <Type>(tuple.Descriptor.FieldTypes, segment.Offset, segment.Length);
            var descriptor = TupleDescriptor.Create(types.AsEnumerable());
            var transform  = new MapTransform(false, descriptor, map);

            return(transform.Apply(TupleTransformType.TransformedTuple, tuple));
        }