Ejemplo n.º 1
0
        public static IQueryable <TTarget> Build <TSource, TTarget>(IQueryable <TSource> source, ModelConvertOptions options)
        {
            if (options == null)
            {
                options = ModelConvert.Target <TTarget>().Source <TSource>().Options.IgnoreReadOnly();
            }

            options.IgnoreReadOnly();

            MemberBindingState state = new MemberBindingState(Expression.Parameter(typeof(TSource), "obj"));

            ModelConvert.WalkConvertiblProperties(null, ModelInfo.GetModelInfo(typeof(TTarget)), null, ModelInfo.GetModelInfo(typeof(TSource)), options, BuildProperty, state);

            var body = Expression.MemberInit(Expression.New(typeof(TTarget)), state.Bindings);

            var lambda = Expression.Lambda <Func <TSource, TTarget> >(body, state.Parameter);

            return(source.Select(lambda));
        }
Ejemplo n.º 2
0
        protected virtual ModelConvertOptions CreateConvertOptions(EntityAction action)
        {
            var options = new ModelConvertOptions();

            if (action == EntityAction.ToModel)
            {
                options.Target <TModel>().Source <TEntity>();
            }
            else
            {
                options.Target <TEntity>().Source <TModel>();
            }

            options.IgnoreReadOnly();

            if (action == EntityAction.Modify)
            {
                options.Target <TEntity>().IgnoreKeys();
            }

            return(options);
        }