Ejemplo n.º 1
0
        public static HbmMapping GetMapings(ObjectRelationalMapper orm)
        {

            domainEntities =
                typeof(Entity).Assembly.GetTypes()
                    .Where(t => typeof(Entity).IsAssignableFrom(t) && !t.IsGenericType)
                    .ToList();
            orm.Cascade<Claim, CPS.Domain.Action>(CascadeOn.None);
            orm.Cascade<Branch, Claim>(CascadeOn.None);
            orm.Cascade<Domain.Action,Document>(CascadeOn.All);

            orm.Component<Address>();
            orm.Component<Incident>();
            orm.Component<ContactInfo>();

            var patterns = new SafePropertyAccessorPack().Merge(new OneToOneRelationPack(orm))
                .Merge(new BidirectionalManyToManyRelationPack(orm))
                .Merge(new BidirectionalOneToManyRelationPack(orm))
                .Merge(new DiscriminatorValueAsClassNamePack(orm))
                .Merge(new CoolColumnsNamingPack(orm))
                .Merge(new TablePerClassPack())
                .Merge(new ListIndexAsPropertyPosColumnNameApplier())
                .Merge(new PluralizedTablesPack(orm, new EnglishInflector()))
                .Merge(new MsSQL2008DateTimeApplier());


            var mapper = new Mapper(orm, patterns);

            var mapping = mapper.CompileMappingFor(domainEntities);
            Debug.WriteLine(mapping.AsString());
            return mapping;
        }
Ejemplo n.º 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 WhenInBaseClassThenNotRecognizeExplicitRegisteredAsSetProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Set<A>(x => x.Set);
     var mi = typeof(B).GetProperty("Set");
     mapper.IsBag(mi).Should().Be.False();
 }
 public void NotRecognizeExplicitRegisteredAsBagProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Bag<A>(x => x.Array);
     var mi = typeof(A).GetProperty("Array");
     mapper.IsArray(mi).Should().Be.False();
 }
        public void ExplicitDeclaration()
        {
            var orm = new ObjectRelationalMapper();
            orm.HeterogeneousAssociation<MyClass>(mc => mc.MyReferenceClass);

            orm.IsHeterogeneousAssociation(typeof(MyClass).GetProperty("MyReferenceClass")).Should().Be.True();
        }
        public void ComposingPatternsAppliersPacksUsingInflector()
        {
            // In this example I'll use the same domain, but composing others packs, changing the strategy for the hierarchy

            var orm = new ObjectRelationalMapper();

            // The follow line show how compose patterns-appliers-packs and patterns-appliers
            IPatternsAppliersHolder patternsAppliers =
                (new SafePropertyAccessorPack())
                    .Merge(new OneToOneRelationPack(orm))
                    .Merge(new BidirectionalManyToManyRelationPack(orm))
                    .Merge(new BidirectionalOneToManyRelationPack(orm))
                    .Merge(new DiscriminatorValueAsClassNamePack(orm))
                    .Merge(new CoolColumnsNamingPack(orm))
                    .Merge(new TablePerClassPack())
                    .Merge(new PluralizedTablesPack(orm, new EnglishInflector()))
                    .Merge(new ListIndexAsPropertyPosColumnNameApplier())
                    .Merge(new DatePropertyByNameApplier())
                    .Merge(new MsSQL2008DateTimeApplier());

            // Instancing the Mapper using the result of Merge
            var mapper = new Mapper(orm, patternsAppliers);

            // Note: I'm declaring the strategy only for the base entity
            orm.TablePerClass<Animal>();

            // Note : I have to create mappings for the whole domain
            var mapping = mapper.CompileMappingFor(typeof(Animal).Assembly.GetTypes().Where(t => t.Namespace == typeof(Animal).Namespace));
            Console.Write(mapping.AsString());
        }
Ejemplo n.º 7
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 NotRecognizeExplicitRegisteredAsListProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.List<A>(x => x.List);
     var mi = typeof(A).GetProperty("List");
     mapper.IsBag(mi).Should().Be.False();
 }
Ejemplo n.º 9
0
        public void ComposingPatternsAppliersPacks()
        {
            // Thanks to Lorenzo Vegetti to provide the domain of this example.
            // This example refers to a little-domain, interesting from the point of view of mapping with ConfORM.
            // Here you can see how apply general convetion, how and when compose patterns-appliers-packs and patterns-appliers,
            // how ConfORM can apply different mapping depending on the type of enum (see the difference on CostOptions) and so on...
            // You don't have to organize the mapping all in one class, as in this example, and you don't have to use the IModuleMapping...
            // You can organize the mapping as you feel more confortable for your application; in some case a class is enough, in other cases would
            // be better the separation per module/concern, you are not closed in "mapping per class" box.

            var orm = new ObjectRelationalMapper();

            // With the follow line I'm adding the pattern for the POID strategy ("native" instead the default "High-Low")
            orm.Patterns.PoidStrategies.Add(new NativePoidPattern());

            // composition of patterns-appliers-packs and patterns-appliers for Lorenzo's domain
            // Note: for bidirectional-one-to-many association Lorenzo is not interested in the default cascade behavior,
            // implemented in the BidirectionalOneToManyRelationPack, because he is using a sort of soft-delete in his base class VersionModelBase.
            // He can implements a custom pack of patterns-appliers to manage the situation when classes does not inherits from VersionModelBase by the way
            // he don't want the cascade atall, so the BidirectionalOneToManyInverseApplier will be enough
            IPatternsAppliersHolder patternsAppliers =
                (new SafePropertyAccessorPack())
                    .Merge(new OneToOneRelationPack(orm))
                    .Merge(new BidirectionalManyToManyRelationPack(orm))
                    .Merge(new DiscriminatorValueAsClassNamePack(orm))
                    .Merge(new CoolColumnsNamingPack(orm))
                    .Merge(new TablePerClassPack())
                    .Merge(new PluralizedTablesPack(orm, new EnglishInflector()))
                    .Merge(new ListIndexAsPropertyPosColumnNameApplier())
                    .Merge(new BidirectionalOneToManyInverseApplier(orm))
                    .Merge(new EnumAsStringPack())
                    .Merge(new DatePropertyByNameApplier())
                    .Merge(new MsSQL2008DateTimeApplier());

            // Instancing the Mapper using the result of Merge
            var mapper = new Mapper(orm, patternsAppliers);

            // Setting the version property using the base class
            orm.VersionProperty<VersionModelBase>(v => v.Version);

            // Note: I'm declaring the strategy only for the base entity
            orm.TablePerClassHierarchy<Cost>();
            orm.TablePerClass<EditionQuotation>();
            orm.TablePerClass<ProductQuotation>();
            orm.TablePerClass<Quotation>();

            AppliesGeneralConventions(mapper);

            // EditionQuotation.PrintCost don't use lazy-loading
            mapper.Customize<EditionQuotation>(map => map.ManyToOne(eq => eq.PrintCost, m2o => m2o.Lazy(LazyRelation.NoLazy)));

            // Customizes some others DDL's stuff outside conventions
            CustomizeColumns(mapper);

            // Note : I have to create mappings for the whole domain
            HbmMapping mapping =
                mapper.CompileMappingFor(
                    typeof (GenericModelBase<>).Assembly.GetTypes().Where(t => t.Namespace == typeof (GenericModelBase<>).Namespace));
            Console.Write(mapping.AsString());
        }
 public void RecognizeExplicitRegisteredSetProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Set<A>(x => x.NickNames);
     var mi = typeof(A).GetProperty("NickNames");
     mapper.IsSet(mi).Should().Be.True();
 }
 public void RecognizeExplicitRegisteredDictionaryProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Dictionary<A>(x => x.Emails);
     PropertyInfo mi = typeof(A).GetProperty("Emails");
     mapper.IsDictionary(mi).Should().Be.True();
 }
 public void WhenCalledShouldAddPersistentPropertiesExclusionsPattern()
 {
     var orm = new ObjectRelationalMapper();
     var oldCount = orm.Patterns.PersistentPropertiesExclusions.Count;
     orm.ExcludeProperty(mi=> mi.DeclaringType != typeof(Person));
     orm.Patterns.PersistentPropertiesExclusions.Count.Should().Be(oldCount + 1);
 }
Ejemplo n.º 13
0
 private static HbmMapping GetMapping()
 {
     var orm = new ObjectRelationalMapper();
     var mapper = new Mapper(orm,
     new CoolPatternsAppliersHolder(orm));
     orm.TablePerClassHierarchy<Product>();
     orm.TablePerClass<ActorRole>();
     orm.Patterns.PoidStrategies.Add(
     new GuidOptimizedPoidPattern());
     orm.VersionProperty<Entity>(x => x.Version);
     orm.NaturalId<Product>(p => p.Name);
     orm.Cascade<Movie, ActorRole>(
     Cascade.All | Cascade.DeleteOrphans);
     mapper.AddPropertyPattern(mi =>
     mi.GetPropertyOrFieldType() == typeof(Decimal) &&
     mi.Name.Contains("Price"),
     pm => pm.Type(NHibernateUtil.Currency));
     mapper.AddPropertyPattern(mi =>
     orm.IsRootEntity(mi.DeclaringType) &&
     !"Description".Equals(mi.Name),
     pm => pm.NotNullable(true));
     mapper.Subclass<Movie>(cm =>
     cm.List(movie => movie.Actors,
     colm => colm.Index(
     lim => lim.Column("ActorIndex")), m => { }));
     var domainClasses = typeof(Entity).Assembly.GetTypes()
     .Where(t => typeof(Entity).IsAssignableFrom(t));
     return mapper.CompileMappingFor(domainClasses);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes the mappings.
        /// </summary>
        /// <param name="config">The configuration.</param>
        public static void InitMappings(Configuration config)
        {
            var orm = new ObjectRelationalMapper();

            var mapper = new Mapper(orm);

            mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string) && !mi.Name.EndsWith("Text"), pm => pm.Length(50));
            mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(string) && mi.Name.EndsWith("Text"), pm => pm.Type(NHibernateUtil.StringClob));

            orm.Patterns.PoidStrategies.Add(new AssignedPoidPattern());

            foreach (var componentDbInit in IoC.ResolveAllInstances<IComponentDbInit>())
            {
                componentDbInit.InitMappings(orm, mapper);
            }

            // compile the mapping for the specified entities
            HbmMapping mappingDocument = mapper.CompileMappingFor(ListOfModelTypes());

            // inject the mapping in NHibernate
            config.AddDeserializedMapping(mappingDocument, "Domain");
            // fix up the schema
            SchemaMetadataUpdater.QuoteTableAndColumns(config);

            SessionFactory.SessionFactoryInstance = config.BuildSessionFactory();
        }
 public void ValueTypesAndSystemTypesShouldBeNotComponents()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.IsComponent(typeof(string)).Should().Be.False();
     mapper.IsComponent(typeof(DateTime)).Should().Be.False();
     mapper.IsComponent(typeof(int)).Should().Be.False();
 }
 public void RecognizeExplicitRegisteredAsArrayProperty()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Array<A>(x => x.Bag);
     var mi = typeof(A).GetProperty("Bag");
     mapper.IsArray(mi).Should().Be.True();
 }
        public void WhenExplicitDeclaredThenRecognizeVerion()
        {
            var orm = new ObjectRelationalMapper();
            orm.VersionProperty<MyClass>(myclass => myclass.Version);

            orm.IsVersion(typeof (MyClass).GetProperty("Version")).Should().Be.True();
        }
        public void ComposingPatternsAppliersPacks()
        {
            // In this example I will compose various packs to customize the mapping.
            // The result is the same of ConfOrm.UsageExamples.Packs.SimpleDemo but this time using patterns-appliers-packs composition (instead its short-cut CoolPatternsAppliersHolder).
            // To play with patterns-appliers-packs-composition you need a more complex domain; adding and removing packs you can see
            // how change your mapping.

            // What is a patterns-appliers-pack:
            // It is an implementation of IPatternsAppliersHolder focused in a specific concern;
            // for example CoolTablesAndColumnsNamingPack is focused to set columns and table names.

            var orm = new ObjectRelationalMapper();

            // The follow line show how compose patterns-appliers-packs and patterns-appliers
            IPatternsAppliersHolder patternsAppliers =
                (new SafePropertyAccessorPack())
                    .Merge(new OneToOneRelationPack(orm))
                    .Merge(new BidirectionalManyToManyRelationPack(orm))
                    .Merge(new BidirectionalOneToManyRelationPack(orm))
                    .Merge(new DiscriminatorValueAsClassNamePack(orm))
                    .Merge(new CoolTablesAndColumnsNamingPack(orm))
                    .Merge(new TablePerClassPack())
                    .Merge(new DatePropertyByNameApplier())
                    .Merge(new MsSQL2008DateTimeApplier());

            // Instancing the Mapper using the result of Merge
            var mapper = new Mapper(orm, patternsAppliers);

            // Note: I'm declaring the strategy only for the base entity
            orm.TablePerClassHierarchy<Animal>();

            // Note : I have to create mappings for the whole domain
            var mapping = mapper.CompileMappingFor(typeof(Animal).Assembly.GetTypes().Where(t => t.Namespace == typeof(Animal).Namespace));
            Console.Write(mapping.AsString());
        }
 public void WhenNotRegisteredAsManyToOneRecognizeRelation()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.TablePerClass<AEntity>();
     mapper.TablePerClass<BEntity>();
     mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.True();
     mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.True();
 }
 public void RegisteringComponentAndEntityThrow()
 {
     var mapper = new ObjectRelationalMapper();
     mapper.Component<AComponent>();
     ActionAssert.Throws(() => mapper.TablePerClass<AComponent>()).Should().Be.InstanceOf<MappingException>();
     ActionAssert.Throws(() => mapper.TablePerConcreteClass<AComponent>()).Should().Be.InstanceOf<MappingException>();
     ActionAssert.Throws(() => mapper.TablePerClassHierarchy<AComponent>()).Should().Be.InstanceOf<MappingException>();
 }
 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 RecognizeOneToMany()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Parent>();
            orm.TablePerClass<Image>();

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

            VerifyMapping(mapping);
        }
        public void WhenRegisterExclusionPropertyOnInterfaceThenShouldExcludePropertyOfConcreteImpl()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Person>();
            orm.ExcludeProperty<IEntity>(p => p.Something);

            orm.IsPersistentProperty(ForClass<Person>.Property(p => p.Something)).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 WhenVersionPropertyDefinedOnInterfaceThenRecognizeItOnConcreteClass()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<MyVersionedEntityOnInterface>();
            orm.VersionProperty<IVersionedEntity>(versionedEntity => versionedEntity.Version);

            orm.IsVersion(ForClass<MyVersionedEntityOnInterface>.Property(e => e.Version)).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 WhenRegisterPersistentPropertyOnInterfaceThenShouldRecognizePropertyOfConcreteImpl()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<Person>();
            orm.PersistentProperty<IEntity>(p => p.IsValid);

            orm.IsPersistentProperty(ForClass<Person>.Property(p => p.IsValid)).Should().Be.True();
        }
Ejemplo n.º 29
0
        public void WhenAskForInterfaceThenGetFistEntityImplementingTheInterface()
        {
            var domainAnalyzer = new ObjectRelationalMapper();

            domainAnalyzer.AddToDomain(typeof(MyRelation));
            domainAnalyzer.AddToDomain(typeof(MyRelation1));
            domainAnalyzer.GetBaseImplementors(typeof(IRelation)).Single().Should().Be(typeof(MyRelation));
            domainAnalyzer.GetBaseImplementors(typeof(Relation1)).Single().Should().Be(typeof(MyRelation1));
        }
        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 RecognizeExplicitRegisteredSetProperty()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.Set <A>(x => x.NickNames);
            var mi = typeof(A).GetProperty("NickNames");

            mapper.IsSet(mi).Should().Be.True();
        }
Ejemplo n.º 32
0
        public HbmMapping GetMapping()
        {
            var orm    = new ObjectRelationalMapper();
            var mapper = new Mapper(orm);

            orm.TablePerClass <PocoEntity>();
            orm.TablePerClass <SelfTrackingEntity>();
            return(mapper.CompileMappingFor(new[] { typeof(PocoEntity), typeof(SelfTrackingEntity) }));
        }
Ejemplo n.º 33
0
        public void GetBaseImplementorsShouldReturnOnlyTheFirstBaseClassOfTheHierarchy()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Animal>();
            orm.ManyToMany <Human, Human>();
            orm.AddToDomain(new[] { typeof(Animal), typeof(Reptile), typeof(Lizard), typeof(Mammal), typeof(Human), typeof(DomesticAnimal), typeof(Cat), typeof(Dog) });
            orm.GetBaseImplementors(typeof(Animal)).Should().Have.SameValuesAs(new[] { typeof(Animal) });
        }
        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();
        }
Ejemplo n.º 35
0
        public void NotRecognizeExplicitRegisteredAsListProperty()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.List <A>(x => x.Array);
            var mi = typeof(A).GetProperty("Array");

            mapper.IsArray(mi).Should().Be.False();
        }
Ejemplo n.º 36
0
        public void RecognizeExplicitRegisteredAsArrayProperty()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.Array <A>(x => x.Bag);
            var mi = typeof(A).GetProperty("Bag");

            mapper.IsArray(mi).Should().Be.True();
        }
Ejemplo n.º 37
0
        public void WhenNotRegisteredAsManyToOneRecognizeRelation()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.IsOneToMany(typeof(BEntity), typeof(AEntity)).Should().Be.True();
            mapper.IsManyToOne(typeof(AEntity), typeof(BEntity)).Should().Be.True();
        }
Ejemplo n.º 38
0
        public void RegisteringComponentAndEntityThrow()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.Component <AComponent>();
            Executing.This(() => mapper.TablePerClass <AComponent>()).Should().Throw().And.Exception.Should().Be.InstanceOf <MappingException>();
            Executing.This(() => mapper.TablePerConcreteClass <AComponent>()).Should().Throw().And.Exception.Should().Be.InstanceOf <MappingException>();
            Executing.This(() => mapper.TablePerClassHierarchy <AComponent>()).Should().Throw().And.Exception.Should().Be.InstanceOf <MappingException>();
        }
Ejemplo n.º 39
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Node>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
Ejemplo n.º 40
0
        public void WhenRegisterCollectionToCollectionThenFindRelation()
        {
            var orm = new ObjectRelationalMapper();

            orm.Bidirectional <B, A>(b => b.Generic, a => a.Bag);

            orm.GetBidirectionalMember(typeof(A), ForClass <A> .Property(x => x.Bag), typeof(B)).Should().Be(ForClass <B> .Property(x => x.Generic));
            orm.GetBidirectionalMember(typeof(B), ForClass <B> .Property(x => x.Generic), typeof(A)).Should().Be(ForClass <A> .Property(x => x.Bag));
        }
        public void WhenExplicitRegisteredRecognizeInverseRelationAsImplicit()
        {
            var mapper = new ObjectRelationalMapper();

            mapper.TablePerClass <AEntity>();
            mapper.TablePerClass <BEntity>();
            mapper.ManyToMany <AEntity, BEntity>();
            mapper.IsMasterManyToMany(typeof(BEntity), typeof(AEntity)).Should().Be.False();
        }
        public void WhenExplicitExcludedThenNotTablePerClassHierarchy()
        {
            // To prevent inconsistence
            var orm = new ObjectRelationalMapper();
            orm.TablePerClassHierarchy<ToExcludeImplEntity>();
            orm.Exclude<ToExcludeImplEntity>();

            orm.IsTablePerClassHierarchy(typeof(ToExcludeImplEntity)).Should().Be.False();
        }
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();
            orm.TablePerClass<MyClass>();
            orm.Complex<MyClass>(mc=> mc.Tags);
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(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();
        }
Ejemplo n.º 45
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyClass>();
            orm.Bidirectional <MyClass, Component>(mc => mc.Components, c => c.Owner);
            HbmMapping mapping = GetMapping(orm);

            VerifyMappingContainsClassWithComponentAndParent(mapping);
        }
Ejemplo n.º 46
0
        public void IntegrationWithObjectRelationalMapperRegisteringTheInverse()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyClass>();
            orm.Bidirectional <Component, MyClass>(component => component.Owner, myClass => myClass.Components);
            HbmMapping mapping = GetMapping(orm);

            VerifyMappingContainsClassWithComponentAndParent(mapping);
        }
        public static IEnumerable <Type> RunModuleMapping <T>(ObjectRelationalMapper orm, Mapper mapper)
            where T : IModuleMapping, new()
        {
            IModuleMapping domainMapping = new T();

            domainMapping.DomainDefinition(orm);
            domainMapping.RegisterPatterns(mapper, orm);
            domainMapping.Customize(mapper);
            return(domainMapping.GetEntities());
        }
        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>();
        }
Ejemplo n.º 49
0
        public void WhenInterfaceOnParentThenMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Node>();

            var pattern = new PolymorphismBidirectionalOneToManyMemberPattern(orm);

            pattern.Match(ForClass <Node> .Property(x => x.SubNodes)).Should().Be.True();
        }
Ejemplo n.º 50
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <MyClass>();
            orm.Complex <MonetaryAmount>();
            HbmMapping mapping = GetMapping(orm);

            VerifyMapping(mapping);
        }
        public void WhenExplicitExcludedThenNotTablePerConcreteClass()
        {
            // To prevent inconsistence
            var orm = new ObjectRelationalMapper();

            orm.TablePerConcreteClass <ToExcludeImplEntity>();
            orm.Exclude <ToExcludeImplEntity>();

            orm.IsTablePerConcreteClass(typeof(ToExcludeImplEntity)).Should().Be.False();
        }
        public void WhenNoRegisterExclusionPropertyForInterfaceThenShouldWorkNormally()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();

            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.Something)).Should().Be.True();
            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.IsValid)).Should().Be.False();
            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.Name)).Should().Be.True();
        }
Ejemplo n.º 53
0
        public void CanDiscoverManyToOneFromComponentToEntity()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <AEntity>();
            orm.TablePerClass <BEntity>();
            orm.Component <AComponent>();

            orm.IsManyToOne(typeof(AComponent), typeof(BEntity)).Should().Be.True();
        }
        public void WhenRegisterExclusionPropertyOnInterfaceAndInclusionOnConcreteThenShouldIncludePropertyOfConcreteImpl()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Person>();
            orm.ExcludeProperty <IEntity>(p => p.Something);
            orm.PersistentProperty <Person>(p => p.Something);

            orm.IsPersistentProperty(ForClass <Person> .Property(p => p.Something)).Should().Be.True();
        }
Ejemplo n.º 55
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();
        }
Ejemplo n.º 56
0
        public void WhenInterfaceOnParentAndPropertyExclusionOnImplThenNoMatch()
        {
            var orm = new ObjectRelationalMapper();

            orm.TablePerClass <Node>();
            orm.ExcludeProperty <Node>(x => x.ParentNode);

            var pattern = new PolymorphismBidirectionalOneToManyMemberPattern(orm);

            pattern.Match(ForClass <Node> .Property(x => x.SubNodes)).Should().Be.False();
        }
Ejemplo n.º 57
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

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

            VerifyMapping(mapping);
        }
Ejemplo n.º 58
0
        public void WithoutExplicitCascade()
        {
            var orm = new ObjectRelationalMapper();

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

            VerifyMapping(mapping);
        }
Ejemplo n.º 59
0
        public void WhenEntitiesOfDomainThenOnlyReturnFirstImplementorInTheHierarchy()
        {
            var domainAnalyzer = new ObjectRelationalMapper();

            domainAnalyzer.AddToDomain(typeof(MyRelation));
            domainAnalyzer.AddToDomain(typeof(MyRelation1));
            domainAnalyzer.AddToDomain(typeof(MyRelationLevel1));
            domainAnalyzer.AddToDomain(typeof(MyRelation1Lvel1));
            domainAnalyzer.GetBaseImplementors(typeof(IRelation)).Single().Should().Be(typeof(MyRelation));
            domainAnalyzer.GetBaseImplementors(typeof(Relation1)).Single().Should().Be(typeof(MyRelation1));
        }
Ejemplo n.º 60
0
        public void IntegrationWithObjectRelationalMapper()
        {
            var orm = new ObjectRelationalMapper();

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

            VerifyAEntityMapping(mapping);
        }