Beispiel #1
0
        public HbmMapping CreateMapping()
        {
            var orm = new ObjectRelationalMapper();

            //主键生成策略(自增)
            orm.Patterns.PoidStrategies.Add(new NativePoidPattern());
            var entities = new[]
            {
                typeof(User),
                typeof(PlusMaterial),
                typeof(StockIn),
                typeof(StockInDetail),
                typeof(StockOut),
                typeof(StockOutDetail),
            };
            orm.TablePerClass(entities);

            //关系映射
            orm.ManyToOne<StockInDetail, StockIn>();
            orm.ManyToOne<StockOutDetail, StockOut>();

            //数据库命名规则
            var mapper = new Mapper(orm, new CoolPatternsAppliersHolder(orm));
            orm.TablePerClass(entities);
            var hc = mapper.CompileMappingFor(Assembly.Load("PMMS.Entities").GetTypes());
            return hc;
        }
 public void WhenExplicitRegisteredRecognizeRelation()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.TablePerClass<AEntity>();
     mapper.TablePerClass<BEntity>();
     mapper.ManyToOne<AEntity, BEntity>();
     mapper.IsManyToOne(typeof (AEntity), typeof (BEntity)).Should().Be.True();
 }
Beispiel #3
0
        public void WhenExplicitRegisteredRecognizeInverseRelation()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.ManyToOne <AEntity, BEntity>();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.True();
        }
        public void WhenFindInterfaceForRootClassThenRecognizeRelation()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Contact>();
            orm.TablePerClass<UserGroup>();
            orm.ManyToOne<UserGroup, ISecurity>();

            orm.IsManyToOne(typeof (UserGroup), typeof (ISecurity)).Should().Be.True();
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<AEntity>();
            orm.TablePerClass<BEntity>();
            orm.ManyToOne<AEntity, BEntity>();
            HbmMapping mapping = GetMapping(orm);

            VerifyAEntityMapping(mapping);
        }
        public void WhenFindInterfaceForRootClassInCollectionThenRecognizeRelation()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Contact>();
            orm.TablePerClass <UserGroup>();
            orm.ManyToOne <UserSuperGroup, ISecurity>();

            orm.IsOneToMany(typeof(ISecurity), typeof(UserSuperGroup)).Should().Be.True();
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Person>();
            orm.TablePerClass<Animal>();
            orm.ManyToOne<Person, Animal>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
Beispiel #9
0
        public void WithoutExplicitCascade()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();
            orm.TablePerClass <Animal>();
            orm.ManyToOne <Person, Animal>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
Beispiel #12
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

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

            VerifyAEntityMapping(mapping);
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<AEntity>();
            orm.TablePerClass<BEntity>();
            orm.ManyToOne<AEntity, BEntity>();
            orm.Cascade<AEntity, BEntity>(Cascade.Persist | Cascade.Remove);
            HbmMapping mapping = GetMapping(orm);

            VerifyMappingWithCascade(mapping);
        }
Beispiel #14
0
        public void WithExplicitCascadeToAll()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            orm.Cascade <Parent, Child>(CascadeOn.All | CascadeOn.DeleteOrphans);
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
Beispiel #15
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

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

            VerifyMappingWithCascade(mapping);
        }
        public void WhenOrmCascadeIsAllThenApplyOndeleteCascade()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            orm.Cascade<Parent, Child>(Cascade.All);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var relation = rc.Properties.First(p => p.Name == "Children");
            var collection = (HbmBag)relation;
            collection.Key.ondelete.Should().Be(HbmOndelete.Cascade);
        }
        public void WhenOrmCascadeDoesNotIncludeDeleteNorDeleteOrhphanThenNotApplyOndeleteCascade()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            orm.Cascade<Parent, Child>(Cascade.Persist | Cascade.ReAttach);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var relation = rc.Properties.First(p => p.Name == "Children");
            var collection = (HbmBag)relation;
            collection.Key.ondelete.Should().Be(HbmOndelete.Noaction);
        }
Beispiel #18
0
        public void WhenOrmCascadeDoesNotIncludeDeleteNorDeleteOrhphanThenNotApplyOndeleteCascade()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            orm.Cascade <Parent, Child>(CascadeOn.Persist | CascadeOn.ReAttach);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc         = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var      relation   = rc.Properties.First(p => p.Name == "Children");
            var      collection = (HbmBag)relation;

            collection.Key.ondelete.Should().Be(HbmOndelete.Noaction);
        }
Beispiel #19
0
        public void WithExplicitCascadeToNone()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            orm.Cascade <Parent, Child>(CascadeOn.None);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc         = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var      relation   = rc.Properties.First(p => p.Name == "Children");
            var      collection = (HbmBag)relation;

            collection.Cascade.Satisfy(c => string.IsNullOrEmpty(c));
        }
Beispiel #20
0
        public void WhenOrmCascadeIsAllThenApplyOndeleteCascade()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Parent>();
            orm.TablePerClass <Child>();
            orm.ManyToOne <Child, Parent>();
            orm.Cascade <Parent, Child>(CascadeOn.All);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc         = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var      relation   = rc.Properties.First(p => p.Name == "Children");
            var      collection = (HbmBag)relation;

            collection.Key.ondelete.Should().Be(HbmOndelete.Cascade);
        }
        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");
        }
Beispiel #22
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 WithExplicitCascadeToNone()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            orm.Cascade<Parent, Child>(Cascade.None);
            HbmMapping mapping = GetMapping(orm);

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Parent"));
            var relation = rc.Properties.First(p => p.Name == "Children");
            var collection = (HbmBag)relation;
            collection.Cascade.Satisfy(c => string.IsNullOrEmpty(c));
        }
        public void WithExplicitCascadeToAll()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            orm.Cascade<Parent, Child>(Cascade.All | Cascade.DeleteOrphans);
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void WithoutExplicitCascade()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Child>();
            orm.ManyToOne<Child, Parent>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }