예제 #1
0
        /// <summary>
        /// Adds a mapping to relate members of one spreadsheet to another by way of a selection query
        /// </summary>
        /// <typeparam name="TSheetData">Class type to return row data as</typeparam>
        /// <typeparam name="TSheetData2">Class of mapped type</typeparam>
        /// <param name="property">Lambda expression that selects the List property to set</param>
        /// <param name="transformation">Lambda expression that selects members from the second worksheet to relate to the first</param>
        /// <param name="worksheet">optional worksheet name</param>
        /// <example>
        /// AddMapping{Group,People}(g => g.GroupMembers, (g,pp) => pp.Where(p => p.GroupId == g.Id);
        /// </example>
        public void AddMapping <TSheetData, TSheetData2>(
            Expression <Func <TSheetData, IList <TSheetData2> > > property,
            Func <TSheetData, IQueryable <TSheetData2>, IQueryable <TSheetData2> > transformation,
            string worksheet = null) where TSheetData : class
        {
            Func <object, IQueryable, IQueryable> function = (t1, qt2) => GetFunction <TSheetData, TSheetData2>(t1, qt2, transformation);

            // Add the boxing operation, but get a weakly typed expression
            Expression converted = Expression.Convert(property.Body, typeof(object));

            // Use Expression.Lambda to get back to strong typing
            var keyProperty = Expression.Lambda <Func <TSheetData, object> >(converted, property.Parameters);

            var tk = GetTransformKey(keyProperty);

            worksheet = worksheet ?? tk.Item2;
            var sheetData2Query = this.Worksheet <TSheetData2>(worksheet);

            _sheetDataIncludes.Add(TransformKey.Create(typeof(TSheetData2), worksheet), sheetData2Query);

            _foreignKeyTransformations.Add(tk, Tuple.Create(worksheet, function));
        }
예제 #2
0
 private TransformKey GetTransformKey <TSheetData>(Expression <Func <TSheetData, object> > property)
 {
     return(TransformKey.Create(typeof(TSheetData), GetPropertyName(property)));
 }