public void ComponentMappingJustOnceDemo()
        {
            var mapper = new ModelMapper();

            mapper.Component <Name>(comp =>
            {
                comp.Property(name => name.First);
                comp.Property(name => name.Last);
            });
            mapper.Component <Address>(comp =>
            {
                comp.Property(address => address.CivicNumber);
                comp.Property(address => address.Street);
            });
            mapper.Class <Person1>(cm =>
            {
                cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
                cm.Property(person => person.Test);
                cm.Component(person => person.Name, comp => { });
                cm.Component(person => person.Address, comp => { });
            });

            var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            var hbmClass = hbmMapping.RootClasses[0];

            var hbmComponents = hbmClass.Properties.OfType <HbmComponent>();

            hbmComponents.Should().Have.Count.EqualTo(2);
            hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name", "Address");
        }
		public void ComponentMappingJustOnceDemo()
		{
			var mapper = new ModelMapper();
			mapper.Component<Name>(comp =>
			{
				comp.Property(name => name.First);
				comp.Property(name => name.Last);
			});
			mapper.Component<Address>(comp =>
			{
				comp.Property(address => address.CivicNumber);
				comp.Property(address => address.Street);
			});
			mapper.Class<Person1>(cm =>
			{
				cm.Id(person => person.Id, map => map.Generator(Generators.HighLow));
				cm.Property(person => person.Test);
				cm.Component(person => person.Name, comp => { });
				cm.Component(person => person.Address, comp => { });
			});

			var hbmMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

			var hbmClass = hbmMapping.RootClasses[0];

			var hbmComponents = hbmClass.Properties.OfType<HbmComponent>();
			hbmComponents.Should().Have.Count.EqualTo(2);
			hbmComponents.Select(x => x.Name).Should().Have.SameValuesAs("Name","Address");
		} 
Example #3
0
        public void ApplyTo(Configuration configuration)
        {
            var mapper = new ModelMapper();
            mapper.Class<Node>(node =>
            {
                node.Id(x => x.Id, map =>
                {
                    map.Column("NodeId");
                    map.Generator(Generators.GuidComb);
                });
                node.Property(x => x.Name, map =>
                {
                    map.Length(50);
                    map.Column("NodeName");
                });
                node.Bag(x => x.Connections, bag =>
                {
                    bag.Key(key =>
                    {
                        key.Column("StartNodeId");
                        key.ForeignKey("FK_RelatedNode_Node_StartNodeId");
                    });
                    bag.Table("Connection");
                    bag.Cascade(Cascade.All.Include(Cascade.Remove));
                    bag.Fetch(CollectionFetchMode.Subselect);
                });
            });

            mapper.Component<Connection>(connection =>
            {
                connection.Parent(x => x.Start);
                connection.ManyToOne(x => x.End, manyToOne =>
                {
                    manyToOne.Column("EndNodeId");
                    manyToOne.ForeignKey("FK_RelatedNode_Node_EndNodeId");
                    manyToOne.Cascade(Cascade.Persist);
                    manyToOne.NotNullable(true);
                });
                connection.Component(x => x.Quality, c => {});
            });

            mapper.Component<ConnectionQuality>(connectionQuality =>
            {
                connectionQuality.Property(x => x.UploadMbps);
                connectionQuality.Property(x => x.DownloadMbps);
            });
            configuration.AddMapping(mapper.CompileMappingForAllExplicitAddedEntities());
        }
		public void WhenAClassIsExplicitlyDeclaredAsComponentThenIsComponent()
		{
			var autoinspector = new SimpleModelInspector();
			var mapper = new ModelMapper(autoinspector);
			mapper.Component<AEntity>(map => { });

			var inspector = (IModelInspector)autoinspector;
			Assert.That(inspector.IsComponent(typeof(AEntity)), Is.True);
		}
Example #5
0
        public void TestMapComponentEntity()
        {
            var cfg    = new Configuration().Configure();
            var mapper = new ModelMapper();

            mapper.Class <ClassWithMapComponentEntity>(c =>
            {
                c.Lazy(false);
                c.Id(id => id.Id, id =>
                {
                    id.Generator(Generators.Identity);
                });

                c.Map(m => m.Map, col =>
                {
                    col.Table("component_entity");
                    col.Key(k => k.Column("id"));
                }, key =>
                {
                    key.Component(cmp =>
                    {
                        cmp.Property(p => p.A);
                        cmp.Property(p => p.B);
                    });
                }, element =>
                {
                    element.ManyToMany(e =>
                    {
                        e.Column("element");
                    });
                });
            });

            mapper.Component <Component>(c =>
            {
                c.Property(p => p.A);
                c.Property(p => p.B);
            });

            mapper.Class <Entity>(c =>
            {
                c.Lazy(false);
                c.Id(id => id.A, id =>
                {
                    id.Generator(Generators.Identity);
                });
                c.Property(p => p.B);
            });

            cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            var script = cfg.GenerateSchemaCreationScript(new MsSql2012Dialect());

            Assert.False(script.Any(x => x.Contains("idx")));
        }
        public void WhenAClassIsExplicitlyDeclaredAsComponentThenIsComponent()
        {
            var autoinspector = new SimpleModelInspector();
            var mapper        = new ModelMapper(autoinspector);

            mapper.Component <AEntity>(map => { });

            var inspector = (IModelInspector)autoinspector;

            inspector.IsComponent(typeof(AEntity)).Should().Be.True();
        }
		private HbmMapping GetMappingWithParentInCompo()
		{
			var mapper = new ModelMapper();
			mapper.Class<MyClass>(x =>
			{
				x.Id(c => c.Id);
				x.Component(c => c.Compo);
				x.Bag(c => c.Compos, cm => { });
			});
			mapper.Component<MyCompo>(x =>
			{
				x.Parent(c => c.AManyToOne);
				x.Component(c => c.NestedCompo);
			});
			mapper.Component<MyNestedCompo>(x =>
			{
				x.Component(c => c.Owner);
				x.Property(c => c.Something);
			});
			return mapper.CompileMappingForAllExplicitlyAddedEntities();
		}
		public void WhenMapClasByClassThenAutodiscoverParent()
		{
			var mapper = new ModelMapper();
			mapper.Component<Address>(cm =>
			{
				cm.ManyToOne(x => x.Owner);
				cm.Property(x => x.Street);
				cm.Component(x => x.Number, y => { });
			});
			mapper.Component<Number>(cm =>
			{
				cm.Component(x => x.OwnerAddress, map => { });
				cm.Property(x => x.Block);
			});
			mapper.Class<Person>(cm =>
			{
				cm.Id(x => x.Id);
				cm.Bag(x => x.Addresses, cp => { }, cr => { });
			});
			HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });
			VerifyMapping(mapping);
		}
Example #9
0
        private HbmMapping GetMappingWithParentInCompo()
        {
            var mapper = new ModelMapper();

            mapper.Class <MyClass>(x =>
            {
                x.Id(c => c.Id);
                x.Component(c => c.Compo);
                x.Bag(c => c.Compos, cm => { });
            });
            mapper.Component <MyCompo>(x =>
            {
                x.Parent(c => c.AManyToOne);
                x.Component(c => c.NestedCompo);
            });
            mapper.Component <MyNestedCompo>(x =>
            {
                x.Component(c => c.Owner);
                x.Property(c => c.Something);
            });
            return(mapper.CompileMappingForAllExplicitlyAddedEntities());
        }
Example #10
0
        public void TestMapComponentEntity()
        {
            var mapper = new ModelMapper();

            mapper.Class <ClassWithMapComponentEntity>(
                c =>
            {
                c.Lazy(false);
                c.Id(id => id.Id, id => id.Generator(Generators.Identity));

                c.Map(
                    m => m.Map,
                    col =>
                {
                    col.Table("component_entity");
                    col.Key(k => k.Column("id"));
                },
                    key => key.Component(
                        cmp =>
                {
                    cmp.Property(p => p.A);
                    cmp.Property(p => p.B);
                }),
                    element => element.ManyToMany(e => e.Column("element")));
            });

            mapper.Component <Component>(
                c =>
            {
                c.Property(p => p.A);
                c.Property(p => p.B);
            });

            mapper.Class <Entity>(
                c =>
            {
                c.Lazy(false);
                c.Id(id => id.A, id => id.Generator(Generators.Identity));
                c.Property(p => p.B);
            });

            var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
            var hbmClass = mappings.RootClasses.FirstOrDefault(c => c.Name == typeof(ClassWithMapComponentEntity).Name);
            var hbmMap   = hbmClass.Properties.OfType <HbmMap>().SingleOrDefault();

            Assert.That(hbmMap, Is.Not.Null);
            Assert.That(hbmMap.Item, Is.TypeOf <HbmCompositeMapKey>());
            Assert.That(hbmMap.Item1, Is.TypeOf <HbmManyToMany>());
        }
        public void WhenMapClasByClassThenAutodiscoverParent()
        {
            var mapper = new ModelMapper();

            mapper.Component <Address>(cm =>
            {
                cm.ManyToOne(x => x.Owner);
                cm.Property(x => x.Street);
                cm.Component(x => x.Number, y => { });
            });
            mapper.Component <Number>(cm =>
            {
                cm.Component(x => x.OwnerAddress, map => { });
                cm.Property(x => x.Block);
            });
            mapper.Class <Person>(cm =>
            {
                cm.Id(x => x.Id);
                cm.Bag(x => x.Addresses, cp => { }, cr => { });
            });
            HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });

            VerifyMapping(mapping, false, "Street", "Number", "Owner");
        }
        public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationOverrideThenUseComponentAsIdCustomization()
        {
            var mapper = new ModelMapper();

            mapper.Component <IMyCompo>(x =>
            {
                x.Access(Accessor.Field);
                x.Class <MyComponent>();
            });
            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id, idmap => idmap.Access(Accessor.NoSetter)));

            var hbmMapping    = mapper.CompileMappingFor(new[] { typeof(MyClass) });
            var hbmClass      = hbmMapping.RootClasses[0];
            var hbmCompositId = hbmClass.CompositeId;

            hbmCompositId.access.Should().Contain("nosetter");
            [email protected]().Contain("MyComponent");
        }
Example #13
0
        public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseInComponentAsIdCustomization()
        {
            var mapper = new ModelMapper();

            mapper.Component <IMyCompo>(x =>
            {
                x.Access(Accessor.Field);
                x.Class <MyComponent>();
            });
            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id));

            var hbmMapping    = mapper.CompileMappingFor(new[] { typeof(MyClass) });
            var hbmClass      = hbmMapping.RootClasses[0];
            var hbmCompositId = hbmClass.CompositeId;

            Assert.That(hbmCompositId.access, Does.Contain("field"));
            Assert.That(hbmCompositId.@class, Does.Contain("MyComponent"));
        }
Example #14
0
        public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
        {
            var mapper = new ModelMapper();

            mapper.Component <IMyCompo>(x =>
            {
                x.Property(y => y.Code, pm => pm.Length(10));
                x.Property(y => y.Name);
            });
            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id));

            var hbmMapping    = mapper.CompileMappingFor(new[] { typeof(MyClass) });
            var hbmClass      = hbmMapping.RootClasses[0];
            var hbmCompositId = hbmClass.CompositeId;
            var keyProperties = hbmCompositId.Items.OfType <HbmKeyProperty>();

            Assert.That(keyProperties.Count(), Is.EqualTo(2));
            Assert.That(keyProperties.Select(x => x.Name), Is.EquivalentTo(new [] { "Code", "Name" }));
            Assert.That(keyProperties.Single(x => x.Name == "Code").length, Is.EqualTo("10"));
        }
        protected override HbmMapping GetMappings()
        {
            var mapper = new ModelMapper();

            mapper.Component <Person>(comp =>
            {
                comp.Property(p => p.Name);
                comp.Property(p => p.Dob);
                comp.Unique(true);                 // hbm2ddl: Generate a unique constraint in the database
            });

            mapper.Class <Employee>(cm =>
            {
                cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow));
                cm.Property(employee => employee.HireDate);
                cm.Component(person => person.Person);
            });

            return(mapper.CompileMappingForAllExplicitlyAddedEntities());
        }
		protected override HbmMapping GetMappings()
		{
			var mapper = new ModelMapper();

			mapper.Component<Person>(comp =>
			{
				comp.Property(p => p.Name);
				comp.Property(p => p.Dob);
				comp.Unique(true); // hbm2ddl: Generate a unique constraint in the database
			});

			mapper.Class<Employee>(cm =>
			{
				cm.Id(employee => employee.Id, map => map.Generator(Generators.HighLow));
				cm.Property(employee => employee.HireDate);
				cm.Component(person => person.Person);
			});

			return mapper.CompileMappingForAllExplicitlyAddedEntities();
		}
        public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
        {
            var mapper = new ModelMapper();

            mapper.Component <IMyCompo>(x =>
            {
                x.Property(y => y.Code, pm => pm.Length(10));
                x.Property(y => y.Name);
            });
            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id));

            var hbmMapping    = mapper.CompileMappingFor(new[] { typeof(MyClass) });
            var hbmClass      = hbmMapping.RootClasses[0];
            var hbmCompositId = hbmClass.CompositeId;
            var keyProperties = hbmCompositId.Items.OfType <HbmKeyProperty>();

            keyProperties.Should().Have.Count.EqualTo(2);
            keyProperties.Select(x => x.Name).Should().Have.SameValuesAs("Code", "Name");
            keyProperties.Where(x => x.Name == "Code").Single().length.Should().Be("10");
        }
        public void WhenMapCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseComponentAsIdCustomization()
        {
            var mapper = new ModelMapper();

            mapper.Component <IMyCompo>(x =>
            {
                x.Property(y => y.Code, pm => pm.Length(10));
                x.Property(y => y.Name, pm => pm.Length(20));
            });
            mapper.Class <MyClass>(map => map.ComponentAsId(x => x.Id, idmap =>
            {
                idmap.Property(y => y.Code, pm => pm.Length(15));
                idmap.Property(y => y.Name, pm => pm.Length(25));
            }));

            var hbmMapping    = mapper.CompileMappingFor(new[] { typeof(MyClass) });
            var hbmClass      = hbmMapping.RootClasses[0];
            var hbmCompositId = hbmClass.CompositeId;
            var keyProperties = hbmCompositId.Items.OfType <HbmKeyProperty>();

            keyProperties.Select(x => x.length).Should().Have.SameValuesAs("15", "25");
        }
Example #19
0
		public static HbmMapping GetMapping()
		{
			var mapper = new ModelMapper();

			mapper.Component<Address>(comp =>
			{
				comp.Property(address => address.Street);
				comp.Property(address => address.City);
				comp.Property(address => address.PostalCode);
				comp.Property(address => address.Country);
				comp.ManyToOne(address => address.StateProvince);
			});

			mapper.Class<Animal>(rc => 
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));

				rc.Property(animal => animal.Description);
				rc.Property(animal => animal.BodyWeight);
				rc.ManyToOne(animal => animal.Mother);
				rc.ManyToOne(animal => animal.Father);
				rc.ManyToOne(animal => animal.Zoo);
				rc.Property(animal => animal.SerialNumber);
				rc.Set(animal => animal.Offspring, cm => cm.OrderBy(an => an.Father), rel => rel.OneToMany());
			});

			mapper.JoinedSubclass<Reptile>(jsc => { jsc.Property(reptile => reptile.BodyTemperature); });

			mapper.JoinedSubclass<Lizard>(jsc => { });

			mapper.JoinedSubclass<Mammal>(jsc =>
			{
				jsc.Property(mammal => mammal.Pregnant);
				jsc.Property(mammal => mammal.Birthdate);
			});

			mapper.JoinedSubclass<DomesticAnimal>(jsc =>
			                                      {
			                                      	jsc.ManyToOne(domesticAnimal => domesticAnimal.Owner);
			                                      });

			mapper.JoinedSubclass<Cat>(jsc => { });

			mapper.JoinedSubclass<Dog>(jsc => { });

			mapper.JoinedSubclass<Human>(jsc =>
			{
				jsc.Component(human => human.Name, comp =>
				{
					comp.Property(name => name.First);
					comp.Property(name => name.Initial);
					comp.Property(name => name.Last);
				});
				jsc.Property(human => human.NickName);
				jsc.Property(human => human.Height);
				jsc.Property(human => human.IntValue);
				jsc.Property(human => human.FloatValue);
				jsc.Property(human => human.BigDecimalValue);
				jsc.Property(human => human.BigIntegerValue);
				jsc.Bag(human => human.Friends, cm => { }, rel => rel.ManyToMany());
				jsc.Map(human => human.Family, cm => { }, rel => rel.ManyToMany());
				jsc.Bag(human => human.Pets, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
				jsc.Set(human => human.NickNames, cm =>
				{
					cm.Lazy(CollectionLazy.NoLazy);
					cm.Sort();
				}, cer => { });
				jsc.Map(human => human.Addresses, cm => { }, rel => rel.Component(comp => { }));
			});

			mapper.Class<User>(rc =>
			{
				rc.Id(u => u.Id, im => im.Generator(Generators.Foreign<User>(u => u.Human)));

				rc.Property(user => user.UserName);
				rc.OneToOne(user => user.Human, rm => rm.Constrained(true));
				rc.List(user => user.Permissions, cm => { }, cer => { });
			});

			mapper.Class<Zoo>(rc =>
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));
				rc.Property(zoo => zoo.Name);
				rc.Property(zoo => zoo.Classification);
				rc.Map(zoo => zoo.Mammals, cm => { }, rel => rel.OneToMany());
				rc.Map(zoo => zoo.Animals, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
				rc.Component(zoo => zoo.Address, comp => { });
			});

			mapper.Subclass<PettingZoo>(sc => { });

			mapper.Class<StateProvince>(rc =>
			{
				rc.Id(x => x.Id, map => map.Generator(Generators.Native));
				rc.Property(sp => sp.Name);
				rc.Property(sp => sp.IsoCode);
			});
			return mapper.CompileMappingFor(typeof (Animal).Assembly.GetTypes().Where(t => t.Namespace == typeof (Animal).Namespace));
		}
		public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			                           {
																	 x.Property(y => y.Code, pm => pm.Length(10));
																	 x.Property(y => y.Name);
			                           });
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			keyProperties.Should().Have.Count.EqualTo(2);
			keyProperties.Select(x => x.Name).Should().Have.SameValuesAs("Code", "Name");
			keyProperties.Where(x => x.Name == "Code").Single().length.Should().Be("10");
		}
		public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationOverrideThenUseComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Access(Accessor.Field);
				x.Class<MyComponent>();
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap => idmap.Access(Accessor.NoSetter)));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			hbmCompositId.access.Should().Contain("nosetter");
			[email protected]().Contain("MyComponent");
		}
		public void WhenMapCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Property(y => y.Code, pm=> pm.Length(10));
				x.Property(y => y.Name, pm => pm.Length(20));
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id, idmap =>
			{
				idmap.Property(y => y.Code, pm => pm.Length(15));
				idmap.Property(y => y.Name, pm => pm.Length(25));
			}));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			keyProperties.Select(x => x.length).Should().Have.SameValuesAs("15", "25");
		}
Example #23
0
        public static HbmMapping GetMapping()
        {
            var mapper = new ModelMapper();

            mapper.Component <Address>(comp =>
            {
                comp.Property(address => address.Street);
                comp.Property(address => address.City);
                comp.Property(address => address.PostalCode);
                comp.Property(address => address.Country);
                comp.ManyToOne(address => address.StateProvince);
            });

            mapper.Class <Animal>(rc =>
            {
                rc.Id(x => x.Id, map => map.Generator(Generators.Native));

                rc.Property(animal => animal.Description);
                rc.Property(animal => animal.BodyWeight);
                rc.ManyToOne(animal => animal.Mother);
                rc.ManyToOne(animal => animal.Father);
                rc.ManyToOne(animal => animal.Zoo);
                rc.Property(animal => animal.SerialNumber);
                rc.Set(animal => animal.Offspring, cm => cm.OrderBy(an => an.Father), rel => rel.OneToMany());
            });

            mapper.JoinedSubclass <Reptile>(jsc => { jsc.Property(reptile => reptile.BodyTemperature); });

            mapper.JoinedSubclass <Lizard>(jsc => { });

            mapper.JoinedSubclass <Mammal>(jsc =>
            {
                jsc.Property(mammal => mammal.Pregnant);
                jsc.Property(mammal => mammal.Birthdate);
            });

            mapper.JoinedSubclass <DomesticAnimal>(jsc =>
            {
                jsc.ManyToOne(domesticAnimal => domesticAnimal.Owner);
            });

            mapper.JoinedSubclass <Cat>(jsc => { });

            mapper.JoinedSubclass <Dog>(jsc => { });

            mapper.JoinedSubclass <Human>(jsc =>
            {
                jsc.Component(human => human.Name, comp =>
                {
                    comp.Property(name => name.First);
                    comp.Property(name => name.Initial);
                    comp.Property(name => name.Last);
                });
                jsc.Property(human => human.NickName);
                jsc.Property(human => human.Height);
                jsc.Property(human => human.IntValue);
                jsc.Property(human => human.FloatValue);
                jsc.Property(human => human.BigDecimalValue);
                jsc.Property(human => human.BigIntegerValue);
                jsc.Bag(human => human.Friends, cm => { }, rel => rel.ManyToMany());
                jsc.Map(human => human.Family, cm => { }, rel => rel.ManyToMany());
                jsc.Bag(human => human.Pets, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
                jsc.Set(human => human.NickNames, cm =>
                {
                    cm.Lazy(CollectionLazy.NoLazy);
                    cm.Sort();
                }, cer => { });
                jsc.Map(human => human.Addresses, cm => { }, rel => rel.Component(comp => { }));
            });

            mapper.Class <User>(rc =>
            {
                rc.Id(u => u.Id, im => im.Generator(Generators.Foreign <User>(u => u.Human)));

                rc.Property(user => user.UserName);
                rc.OneToOne(user => user.Human, rm => rm.Constrained(true));
                rc.List(user => user.Permissions, cm => { }, cer => { });
            });

            mapper.Class <Zoo>(rc =>
            {
                rc.Id(x => x.Id, map => map.Generator(Generators.Native));
                rc.Property(zoo => zoo.Name);
                rc.Property(zoo => zoo.Classification);
                rc.Map(zoo => zoo.Mammals, cm => { }, rel => rel.OneToMany());
                rc.Map(zoo => zoo.Animals, cm => { cm.Inverse(true); }, rel => rel.OneToMany());
                rc.Component(zoo => zoo.Address, comp => { });
            });

            mapper.Subclass <PettingZoo>(sc => { });

            mapper.Class <StateProvince>(rc =>
            {
                rc.Id(x => x.Id, map => map.Generator(Generators.Native));
                rc.Property(sp => sp.Name);
                rc.Property(sp => sp.IsoCode);
            });
            return(mapper.CompileMappingFor(typeof(Animal).Assembly.GetTypes().Where(t => t.Namespace == typeof(Animal).Namespace)));
        }
		public void WhenMapComponentUsedAsComponentAsIdThenMapItAndItsProperties()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
									   {
																	 x.Property(y => y.Code, pm => pm.Length(10));
																	 x.Property(y => y.Name);
									   });
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			var keyProperties = hbmCompositId.Items.OfType<HbmKeyProperty>();
			Assert.That(keyProperties.Count(), Is.EqualTo(2));
			Assert.That(keyProperties.Select(x => x.Name), Is.EquivalentTo(new [] {"Code", "Name"}));
			Assert.That(keyProperties.Single(x => x.Name == "Code").length, Is.EqualTo("10"));
		}
Example #25
0
		public void TestMapComponentEntity()
		{
			var cfg = new Configuration().Configure();
			var mapper = new ModelMapper();

			mapper.Class<ClassWithMapComponentEntity>(c =>
			{
				c.Lazy(false);
				c.Id(id => id.Id, id =>
				{
					id.Generator(Generators.Identity);
				});

				c.Map(m => m.Map, col =>
				{
					col.Table("component_entity");
					col.Key(k => k.Column("id"));
				}, key =>
				{
					key.Component(cmp =>
					{
						cmp.Property(p => p.A);
						cmp.Property(p => p.B);
					});
				}, element =>
				{
					element.ManyToMany(e =>
					{
						e.Column("element");
					});
				});
			});

			mapper.Component<Component>(c =>
			{
				c.Property(p => p.A);
				c.Property(p => p.B);
			});

			mapper.Class<Entity>(c =>
			{
				c.Lazy(false);
				c.Id(id => id.A, id =>
				{
					id.Generator(Generators.Identity);
				});
				c.Property(p => p.B);
			});

			cfg.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

			var script = cfg.GenerateSchemaCreationScript(new MsSql2012Dialect());

			Assert.False(script.Any(x => x.Contains("idx")));
		}
		public void WhenMapAttributesOfCustomizedComponentUsedAsComponentAsIdWithCustomizationThenUseInComponentAsIdCustomization()
		{
			var mapper = new ModelMapper();
			mapper.Component<IMyCompo>(x =>
			{
				x.Access(Accessor.Field);
				x.Class<MyComponent>();
			});
			mapper.Class<MyClass>(map => map.ComponentAsId(x => x.Id));

			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });
			var hbmClass = hbmMapping.RootClasses[0];
			var hbmCompositId = hbmClass.CompositeId;
			Assert.That(hbmCompositId.access, Is.StringContaining("field"));
			Assert.That(hbmCompositId.@class, Is.StringContaining("MyComponent"));
		}
Example #27
0
		public void TestMapComponentEntity()
		{
			var mapper = new ModelMapper();

			mapper.Class<ClassWithMapComponentEntity>(
				c =>
				{
					c.Lazy(false);
					c.Id(id => id.Id, id => id.Generator(Generators.Identity));

					c.Map(
						m => m.Map,
						col =>
						{
							col.Table("component_entity");
							col.Key(k => k.Column("id"));
						},
						key => key.Component(
							cmp =>
							{
								cmp.Property(p => p.A);
								cmp.Property(p => p.B);
							}),
						element => element.ManyToMany(e => e.Column("element")));
				});

			mapper.Component<Component>(
				c =>
				{
					c.Property(p => p.A);
					c.Property(p => p.B);
				});

			mapper.Class<Entity>(
				c =>
				{
					c.Lazy(false);
					c.Id(id => id.A, id => id.Generator(Generators.Identity));
					c.Property(p => p.B);
				});

			var mappings = mapper.CompileMappingForAllExplicitlyAddedEntities();
			var hbmClass = mappings.RootClasses.FirstOrDefault(c => c.Name == typeof (ClassWithMapComponentEntity).Name);
			var hbmMap = hbmClass.Properties.OfType<HbmMap>().SingleOrDefault();

			Assert.That(hbmMap, Is.Not.Null);
			Assert.That(hbmMap.Item, Is.TypeOf<HbmCompositeMapKey>());
			Assert.That(hbmMap.Item1, Is.TypeOf<HbmManyToMany>());
		}