Example #1
0
        public when_using_ef()
        {
            var mapperContainer =
                new MapperContainer()
                    .Register<Person, PersonEntity>(
                        (f, t, c) =>
                            {
                                c.Map(f.Name, () => t.Name);
                                c.MapAll(f.Addresses, () => t.Addresses);
                            })
                    .Register<Name, NameEntity>(
                        (f, t, c) =>
                            {
                                t.First = f.First;
                                t.Last = f.Last;
                            }
                    )
                    .Register<Address, AddressEntity>(
                        (f, t, c) => { t.Name = f.Name; }
                    );

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DataContext>());
            _dataContext = new DataContext(mapperContainer);

            _from = new Person
                        {
                            Name = new Name {First = "Person"},
                            Addresses = new[]
                                            {
                                                new Address {Name = "Keep"},
                                                new Address {Name = "New"}
                                            }
                        };

            _to = _dataContext.Create<PersonEntity>();
            _to.Name = new NameEntity {First = "Overwite"};
            _to.Addresses = new[]
                                {
                                    new AddressEntity {Name = "Keep"},
                                    new AddressEntity {Name = "Delete"}
                                };
            _dataContext.SaveChanges();

            var personId = _to.Id;

            _dataContext.Map(_from, () => _to);
            _dataContext.SaveChanges();

            _dataContext = new DataContext(mapperContainer);
            _to = _dataContext
                .People.Include(p => p.Addresses)
                .Single(p => p.Id == personId);
        }
Example #2
0
        public when_using_ef()
        {
            var mapperContainer =
                new MapperContainer()
                .Register <Person, PersonEntity>(
                    (f, t, c) =>
            {
                c.Map(f.Name, () => t.Name);
                c.MapAll(f.Addresses, () => t.Addresses);
            })
                .Register <Name, NameEntity>(
                    (f, t, c) =>
            {
                t.First = f.First;
                t.Last  = f.Last;
            }
                    )
                .Register <Address, AddressEntity>(
                    (f, t, c) => { t.Name = f.Name; }
                    );

            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <DataContext>());
            _dataContext = new DataContext(mapperContainer);

            _from = new Person
            {
                Name = new Name {
                    First = "Person"
                },
                Addresses = new[]
                {
                    new Address {
                        Name = "Keep"
                    },
                    new Address {
                        Name = "New"
                    }
                }
            };

            _to      = _dataContext.Create <PersonEntity>();
            _to.Name = new NameEntity {
                First = "Overwite"
            };
            _to.Addresses = new[]
            {
                new AddressEntity {
                    Name = "Keep"
                },
                new AddressEntity {
                    Name = "Delete"
                }
            };
            _dataContext.SaveChanges();

            var personId = _to.Id;

            _dataContext.Map(_from, () => _to);
            _dataContext.SaveChanges();

            _dataContext = new DataContext(mapperContainer);
            _to          = _dataContext
                           .People.Include(p => p.Addresses)
                           .Single(p => p.Id == personId);
        }