/// <summary> /// Maps all members. /// </summary> /// <param name="expression">The expression.</param> /// <returns> /// The <seealso cref="T:SampleStore.Mapping.IMapping`2" />. /// </returns> public IMapping <TSource, TTarget> Construct(Expression <Func <TSource, TTarget> > expression) { expression.ThrowIfArgumentIsNull(nameof(expression)); _expression.ConstructUsing(expression); return(this); }
/// <summary> /// Tells AutoMapper that when mapping from a T1 to a T2, construct the T2 using a cache /// that is shared across multiple calls to Map. /// Assumes that a call to preserveReferencesState.Initialize{T1, T2} has already been made. /// </summary> public static IMappingExpression <T1, T2> ConstructUsingPreInitialized <T1, T2>(this IMappingExpression <T1, T2> source, IPreserveReferencesState preserveReferencesState) { var cache = preserveReferencesState.GetCache <T1, T2>(); return(source.ConstructUsing(x => cache[x])); }
/// <summary> /// Tells AutoMapper that when mapping from a T1 to a T2, construct the T2 using a cache /// that is shared across multiple calls to Map. /// </summary> public static IMappingExpression <T1, T2> ConstructUsing <T1, T2>(this IMappingExpression <T1, T2> source, IPreserveReferencesState preserveReferencesState, Func <T1, T2> constructor) { preserveReferencesState.Initialize(constructor); var cache = preserveReferencesState.GetCache <T1, T2>(); return(source.ConstructUsing(x => cache[x])); }
public static IMappingExpression <TSource, TDestination> ResolveForTopLevel <TSource, TDestination, TResult>( this IMappingExpression <TSource, TDestination> mappingExpression, Func <TSource, TResult> sourceMember) { return(mappingExpression.ConstructUsing((compositeDetail, context) => { return context.Mapper.Map <TDestination>(sourceMember(compositeDetail)); })); }
public static IMappingExpression <TSrc, TDest> ConstructUsingNHibernate <TSrc, TDest>( this IMappingExpression <TSrc, TDest> expression, Func <ISession> getSession, Func <TSrc, object> getId) where TDest : class, new() { return(expression.ConstructUsing(src => getSession().Get <TDest>(getId(src)) ?? new TDest())); }
public static IMappingExpression <TSource, PropertyGroup> MapPropertyGroupBasicToPropertyGroupPersistence <TSource, TPropertyTypeBasic>( this IMappingExpression <TSource, PropertyGroup> mapping) where TSource : PropertyGroupBasic <TPropertyTypeBasic> where TPropertyTypeBasic : PropertyTypeBasic { return(mapping .ConstructUsing(x => new PropertyGroup(false)) // TODO: we have NO idea of isPublishing here = so what? .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, map => map.Condition(src => src.Id > 0)) .ForMember(dest => dest.Key, map => map.Ignore()) .ForMember(dest => dest.HasIdentity, map => map.Ignore()) .ForMember(dest => dest.DeleteDate, map => map.Ignore()) .ForMember(dest => dest.PropertyTypes, map => map.Ignore())); }
public static IMappingExpression <TDto, TEntity> ConstructUsingExistingObject <TContext, TDto, TEntity>(this IMappingExpression <TDto, TEntity> expression) where TContext : DbContext where TEntity : class, new() where TDto : DtoBase <TContext, TEntity, TDto>, new() { expression.ConstructUsing((src, opts) => { var dbContext = (TContext)opts.Options.Items["DbContext"]; var srcEntity = src.FindItemTrackedForUpdate(dbContext); if (srcEntity == null) { return(dbContext.Set <TEntity>().Create()); } return(srcEntity); }); return(expression); }
public static IMappingExpression <TSource, TDestination> ConstructAndMapUsing <TSource, TDestination>( this IMappingExpression <TSource, TDestination> mappingExpression, Expression <Func <TSource, TDestination> > ctor) { if (ctor.Body is MemberInitExpression memberInitExpression) { var ctorExpressionWithoutMemberInit = Expression.Lambda <Func <TSource, TDestination> >( memberInitExpression.NewExpression, ctor.Parameters); return(mappingExpression .ConstructUsing(ctorExpressionWithoutMemberInit) .MapUsing(ctor)); } throw new ArgumentException("Parameter is not an object initializer expression.", nameof(ctor)); }
public static IMappingExpression <TServiceModel, TModel> ApplyDefaultServiceModelMappingOptions <TServiceModel, TModel>(this IMappingExpression <TServiceModel, TModel> mappingExpression) where TServiceModel : ServiceModelBase where TModel : ModelBase, new() { // try to load the destination object first in stead of creating a new instance immediately mappingExpression = mappingExpression.ConstructUsing((source, context) => { var dbContext = context.GetDbContext(); if (dbContext == null) { return(new TModel()); } var repository = dbContext.Set <TModel>(); var model = repository.FirstOrDefault(x => x.Guid == source.Guid) ?? new TModel(); model.SetUpdateFields(context.GetUserName()); return(model); }); return(mappingExpression); }
public static IMappingExpression <TSource, TDestination> ConstructUsing <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mappingExpression, Expression <Func <TSource, TDestination> > ctor) { return(mappingExpression.ConstructUsing(ctor)); }