예제 #1
0
        static void Main(string[] args)
        {
            using (var unitOfWorkForSource = new UnitOfWorkForAlpha())
            {
                using (var unitOfWorkForDestination = new UnitOfWorkForZeta())
                {
                    var configuration
                        = CreateMappingBetweenUnitOfWorkEntityTypes <
                              EdTech.Data.AlphaSource.Category,
                              EdTech.Data.ZetaDestination.Category
                              >(unitOfWorkForSource, unitOfWorkForDestination);
                    var mapper = configuration.CreateMapper();

                    var categories
                        = unitOfWorkForSource.CategoryRepository.SelectAll()
                          .Select(category => mapper.Map <
                                      EdTech.Data.AlphaSource.Category,
                                      EdTech.Data.ZetaDestination.Category
                                      >(category)).ToList();

                    unitOfWorkForDestination.CategoryRepository.Upsert(categories);
                    Console.WriteLine("Upsert complete.");
                }
            }
        }
예제 #2
0
        static MapperConfiguration CreateMappingBetweenUnitOfWorkEntityTypes <T, U>(
            UnitOfWorkForAlpha source,
            UnitOfWorkForZeta destination,
            bool ignoreNavigationProperties = true
            ) where T : class
        {
            var mapperConfig = new MapperConfiguration(
                cfg =>
            {
                var configuration
                    = cfg.CreateMap <T, U>();
                var propertiesToBeIgnored
                    = source.NavigationPropertiesFor <T>();
                propertiesToBeIgnored
                .Aggregate(configuration, (result, propertyInfo) => result.ForMember(propertyInfo.Name, m => m.Ignore()));
            }
                );

            return(mapperConfig);
        }