예제 #1
0
        public void DefiningAndCustomizingVersionThroughBaseImplementation()
        {
            // In this example I'll show how you can work with Version and how ConfORM understands OOP

            var orm = new ObjectRelationalMapper();
            var mapper = new Mapper(orm, new CoolPatternsAppliersHolder(orm));

            // In this case I will use the definition of table-to-class strategy class by class
            orm.TablePerClass<CurrencyDefinition>();
            orm.TablePerClass<Company>();
            orm.TablePerClass<Customer>();
            orm.TablePerClass<Provider>();

            // Defining relations
            orm.OneToOne<Company, Customer>();
            orm.OneToOne<Company, Provider>();

            // In the follow line I'm defining which is the property used as Version for all classes inherited from VersionedEntity
            orm.VersionProperty<VersionedEntity>(ve=> ve.Version);

            // In the follow line I'm customizing the column-name for the property used as Version for all classes inherited from VersionedEntity....
            // Note : VersionedEntity is not an entity, it is only a base class.
            mapper.Class<VersionedEntity>(cm => cm.Version(ve => ve.Version, vm => vm.Column("Revision")));

            // In the follow line I'm customizing the column-name for the property used as Version only for the class Provider
            // Note : You can move the follow line before the previous and the result does not change, this is because ConfORM can understand
            // which is a base customization and which is the specific customization.
            mapper.Class<Provider>(cm => cm.Version(ve => ve.Version, vm => vm.Column("IncrementalVersion")));

            // Note : I have to create mappings for the whole domain; Entity and VersionedEntity are excluded from de mapping because out-side
            // root-entities hierarchy (root-entities are : CurrencyDefinition, Company, Customer, Provider)
            var mapping = mapper.CompileMappingFor(typeof(Entity).Assembly.GetTypes().Where(t => t.Namespace == typeof(Entity).Namespace));
            Console.Write(mapping.AsString());
        }
예제 #2
0
        public void DefiningAndCustomizingVersionThroughBaseImplementation()
        {
            // In this example I'll show how you can work with Version and how ConfORM understands OOP

            var orm    = new ObjectRelationalMapper();
            var mapper = new Mapper(orm, new CoolPatternsAppliersHolder(orm));

            // In this case I will use the definition of table-to-class strategy class by class
            orm.TablePerClass <CurrencyDefinition>();
            orm.TablePerClass <Company>();
            orm.TablePerClass <Customer>();
            orm.TablePerClass <Provider>();

            // Defining relations
            orm.OneToOne <Company, Customer>();
            orm.OneToOne <Company, Provider>();

            // In the follow line I'm defining which is the property used as Version for all classes inherited from VersionedEntity
            orm.VersionProperty <VersionedEntity>(ve => ve.Version);

            // In the follow line I'm customizing the column-name for the property used as Version for all classes inherited from VersionedEntity....
            // Note : VersionedEntity is not an entity, it is only a base class.
            mapper.Class <VersionedEntity>(cm => cm.Version(ve => ve.Version, vm => vm.Column("Revision")));

            // In the follow line I'm customizing the column-name for the property used as Version only for the class Provider
            // Note : You can move the follow line before the previous and the result does not change, this is because ConfORM can understand
            // which is a base customization and which is the specific customization.
            mapper.Class <Provider>(cm => cm.Version(ve => ve.Version, vm => vm.Column("IncrementalVersion")));

            // Note : I have to create mappings for the whole domain; Entity and VersionedEntity are excluded from de mapping because out-side
            // root-entities hierarchy (root-entities are : CurrencyDefinition, Company, Customer, Provider)
            var mapping = mapper.CompileMappingFor(typeof(Entity).Assembly.GetTypes().Where(t => t.Namespace == typeof(Entity).Namespace));

            Console.Write(mapping.AsString());
        }
        public void WhenNotRegisteredAsEntityNotRecognizeInverseRelation()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.OneToOne <User, Person>();
            mapper.IsOneToOne(typeof(Person), typeof(User)).Should().Be.False();
        }
 public void WhenExplicitRegisteredRecognizeInverseRelationAsImplicit()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.TablePerClass<User>();
     mapper.TablePerClass<Person>();
     mapper.OneToOne<User, Person>();
     mapper.IsMasterOneToOne(typeof(Person), typeof(User)).Should().Be.False();
 }
 public void WhenExplicitRegisteredRecognizeRelation()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.TablePerClass<User>();
     mapper.TablePerClass<Person>();
     mapper.OneToOne<User, Person>();
     mapper.IsOneToOne(typeof(User), typeof(Person)).Should().Be.True();
 }
        public void WhenExplicitRegisteredRecognizeInverseRelationAsImplicit()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <User>();
            mapper.TablePerClass <Person>();
            mapper.OneToOne <User, Person>();
            mapper.IsMasterOneToOne(typeof(Person), typeof(User)).Should().Be.False();
        }
        public void WhenExplicitRegisteredRecognizeRelation()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <User>();
            mapper.TablePerClass <Person>();
            mapper.OneToOne <User, Person>();
            mapper.IsOneToOne(typeof(User), typeof(Person)).Should().Be.True();
        }
        public void DomainDefinition(ObjectRelationalMapper orm)
        {
            orm.TablePerClass<Animal>();
            orm.TablePerClass<User>();
            orm.TablePerClass<StateProvince>();
            orm.TablePerClassHierarchy<Zoo>();

            orm.ManyToMany<Human, Human>();
            orm.OneToOne<User, Human>();
        }
        public void DomainDefinition(ObjectRelationalMapper orm)
        {
            orm.TablePerClass <Animal>();
            orm.TablePerClass <User>();
            orm.TablePerClass <StateProvince>();
            orm.TablePerClassHierarchy <Zoo>();

            orm.ManyToMany <Human, Human>();
            orm.OneToOne <User, Human>();
        }
        public void WhenUnidirectionalOneToOneThenShouldBeManyToOne()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass(new[] {typeof (MyClass), typeof (MyOneClass)});
            orm.OneToOne<MyClass, MyOneClass>();

            orm.IsOneToOne(typeof (MyClass), typeof (MyOneClass)).Should().Be.False();
            orm.IsManyToOne(typeof(MyClass), typeof(MyOneClass)).Should().Be.True();
            orm.IsMasterOneToOne(typeof(MyClass), typeof(MyOneClass)).Should().Be.True();
        }
예제 #11
0
        public void WhenUnidirectionalOneToOneThenShouldBeManyToOne()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass(new[] { typeof(MyClass), typeof(MyOneClass) });
            orm.OneToOne <MyClass, MyOneClass>();

            orm.IsOneToOne(typeof(MyClass), typeof(MyOneClass)).Should().Be.False();
            orm.IsManyToOne(typeof(MyClass), typeof(MyOneClass)).Should().Be.True();
            orm.IsMasterOneToOne(typeof(MyClass), typeof(MyOneClass)).Should().Be.True();
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <AEntity>();
            orm.TablePerClass <BEntity>();
            orm.OneToOne <AEntity, BEntity>();
            HbmMapping mapping = GetMapping(orm);

            VerifyAEntityMapping <HbmManyToOne>(mapping);
        }
        public void WhenExplicitRegisteredAsOneToOneNotRecognizeRelation()
        {
            var mapper = new ObjectRelationalMapper();
            mapper.TablePerClass<AEntity>();
            mapper.TablePerClass<BEntity>();
            mapper.OneToOne<AEntity, BEntity>();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();

            // the default behaviour map an unidirectional one-to-one as a many-to-one (for NHibernate)
            // mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.False();
        }
예제 #14
0
        public void WhenExplicitRegisteredAsOneToOneNotRecognizeRelation()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.OneToOne <AEntity, BEntity>();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();

            // the default behaviour map an unidirectional one-to-one as a many-to-one (for NHibernate)
            // mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.False();
        }
        public void WhenIsManyToOneAndMasterOneToOneThenApplyUniqueAndCascadeOnAssociationProperty()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass(new[] { typeof(Customer), typeof(Address) });
            orm.OneToOne<Customer, Address>();

            var mapper = new Mapper(orm);
            var mappings = mapper.CompileMappingFor(new[] {typeof (Customer)});

            HbmClass customer = mappings.RootClasses.Single();
            HbmManyToOne customerAddress = customer.Properties.OfType<HbmManyToOne>().Single();

            customerAddress.unique.Should().Be.True();
            customerAddress.cascade.Should().Be("all");
        }
		public void WhenIsManyToOneAndMasterOneToOneThenApplyUniqueAndCascadeOnAssociationProperty()
		{
			var orm = new ObjectRelationalMapper();
			orm.TablePerClass(new[] { typeof(Customer), typeof(Address) });
			orm.OneToOne<Customer, Address>();

			var mapper = new Mapper(orm);
			var mappings = mapper.CompileMappingFor(new[] {typeof (Customer)});

			HbmClass customer = mappings.RootClasses.Single();
			HbmManyToOne customerAddress = customer.Properties.OfType<HbmManyToOne>().Single();

			customerAddress.unique.Should().Be.True();
			customerAddress.cascade.Should().Be("all");
		}
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<AEntity>();
            orm.TablePerClass<BEntity>();
            orm.OneToOne<AEntity, BEntity>();
            orm.Cascade<AEntity, BEntity>(Cascade.Persist | Cascade.Remove);
            HbmMapping mapping = GetMapping(orm);

            // the default behaviour map an unidirectional one-to-one as a many-to-one (for NHibernate)
            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("AEntity"));
            rc.Properties.Should().Have.Count.EqualTo(2);
            rc.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Name", "B");
            var relation = rc.Properties.First(p => p.Name == "B");
            ((HbmManyToOne)relation).cascade.Should().Contain("persist").And.Contain("delete");
        }
        public void IntegrationWithOrmWhenCustomerIsTheMaster()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass(new[] {typeof (Customer), typeof (Address)});
            orm.ManyToOne<Customer, Address>();
            orm.OneToOne<Address, Customer>();

            var mapper = new Mapper(orm);
            var mappings = mapper.CompileMappingFor(new[] { typeof(Customer), typeof(Address) });

            HbmClass customer = mappings.RootClasses.Single(c=> c.Name.Contains("Customer"));
            HbmManyToOne customerAddress = customer.Properties.OfType<HbmManyToOne>().Single();
            customerAddress.unique.Should().Be.True();
            customerAddress.cascade.Should().Be("all");

            HbmClass address = mappings.RootClasses.Single(c => c.Name.Contains("Address"));
            HbmOneToOne addressCustomer = address.Properties.OfType<HbmOneToOne>().Single();
            addressCustomer.propertyref.Should().Be("Address");
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <AEntity>();
            orm.TablePerClass <BEntity>();
            orm.OneToOne <AEntity, BEntity>();
            orm.Cascade <AEntity, BEntity>(Cascade.Persist | Cascade.Remove);
            HbmMapping mapping = GetMapping(orm);

            // the default behaviour map an unidirectional one-to-one as a many-to-one (for NHibernate)
            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("AEntity"));

            rc.Properties.Should().Have.Count.EqualTo(2);
            rc.Properties.Select(p => p.Name).Should().Have.SameValuesAs("Name", "B");
            var relation = rc.Properties.First(p => p.Name == "B");

            ((HbmManyToOne)relation).cascade.Should().Contain("persist").And.Contain("delete");
        }
예제 #20
0
        public void IntegrationWithOrmWhenCustomerIsTheMaster()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass(new[] { typeof(Customer), typeof(Address) });
            orm.ManyToOne <Customer, Address>();
            orm.OneToOne <Address, Customer>();

            var mapper   = new Mapper(orm);
            var mappings = mapper.CompileMappingFor(new[] { typeof(Customer), typeof(Address) });

            HbmClass     customer        = mappings.RootClasses.Single(c => c.Name.Contains("Customer"));
            HbmManyToOne customerAddress = customer.Properties.OfType <HbmManyToOne>().Single();

            customerAddress.unique.Should().Be.True();
            customerAddress.cascade.Should().Be("all");

            HbmClass    address         = mappings.RootClasses.Single(c => c.Name.Contains("Address"));
            HbmOneToOne addressCustomer = address.Properties.OfType <HbmOneToOne>().Single();

            addressCustomer.propertyref.Should().Be("Address");
        }
 public void WhenNotRegisteredAsEntityNotRecognizeRelation()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.OneToOne<User, Person>();
     mapper.IsOneToOne(typeof(User), typeof(Person)).Should().Be.False();
 }