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()); }
public void ApplyFieldAccessor_AsDefaultAccess() { // In this example I will compose various packs to customize the mapping. // There only one pack that is matter of the demo, the other are to have a right/nice mapping. // see also ConfOrm.UsageExamples.Packs.CompositionDemo var orm = new ObjectRelationalMapper(); // The follow line show how compose patterns-appliers-packs and patterns-appliers IPatternsAppliersHolder patternsAppliers = (new AccessToPropertyWhereNoFieldPack()) // <== in this case I'll apply a default-access for the whole mapping, but there are cases where the field does not exists (let ConfORM check it ;) ) .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new CoolTablesAndColumnsNamingPack(orm)) .Merge(new TablePerClassPack()); // Instancing the Mapper using the result of Merge var mapper = new Mapper(orm, patternsAppliers); orm.TablePerClass <Person>(); var mapping = mapper.CompileMappingFor(new[] { typeof(Person) }); mapping.defaultaccess = "field.camelcase"; // <== HERE I'm applying the default-access for all classes in the mapping of the whole domain // In the out-put you will see that the accessor is specified only where the field is not available Console.Write(mapping.AsString()); }
public void DiscriminatorValuePatternsAppliersPacksComposition() { // In this example I will compose various packs to customize the mapping. // In this case I concern on the two packs about Table-per-class-hierarchy discriminator value pattern // Note: both DiscriminatorValueAsClassNamePack and DiscriminatorValueAsEnumValuePack does contain DiscriminatorColumnNameApplier but with the Merge // it will be applied just once 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)) // <== NOTE: it can be used together with DiscriminatorValueAsEnumValuePack .Merge(new DiscriminatorValueAsEnumValuePack <Item, ItemTypes>(orm)) // <== NOTE: it can be used together with DiscriminatorValueAsClassNamePack .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 entities orm.TablePerClassHierarchy <Item>(); orm.TablePerClassHierarchy <Something>(); // Note : I have to create mappings for the whole domain var mapping = mapper.CompileMappingFor(typeof(Item).Assembly.GetTypes().Where(t => t.Namespace == typeof(Item).Namespace)); Console.Write(mapping.AsString()); }
public void ApplyFieldAccessor_PropertyPerProperty_WherePossible() { // In this example I will compose various packs to customize the mapping. // There only one pack that is matter of the demo, the other are to have a right/nice mapping. // see also ConfOrm.UsageExamples.Packs.CompositionDemo var orm = new ObjectRelationalMapper(); // The follow line show how compose patterns-appliers-packs and patterns-appliers IPatternsAppliersHolder patternsAppliers = (new AlwaysAccessToFieldWhereAvailablePack()) // <== in gerenal you have seen SafePropertyAccessorPack but this time I'm applying another pack .Merge(new NoPoidGuidApplier()) // only if you need Entities with neither a property nor a field representing the POID .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new CoolTablesAndColumnsNamingPack(orm)) .Merge(new TablePerClassPack()); // Instancing the Mapper using the result of Merge var mapper = new Mapper(orm, patternsAppliers); orm.TablePerClass <Person>(); var mapping = mapper.CompileMappingFor(new[] { typeof(Person) }); // In the out-put you will see that the accessor to the field will be applied only where possible Console.Write(mapping.AsString()); }
public void ComposingPatternsAppliersPacksUsingInflector() { // In this example you can see how use the inflector adding some special class name translation. var orm = new ObjectRelationalMapper(); // Creation of inflector adding some special class name translation var inflector = new SpanishInflector(); AddCustomData_Dictionary(inflector); 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, inflector)) // <=== .Merge(new ListIndexAsPropertyPosColumnNameApplier()); // Instancing the Mapper using the result of Merge var mapper = new Mapper(orm, patternsAppliers); orm.TablePerClass <UsuarioWeb>(); var mapping = mapper.CompileMappingFor(new[] { typeof(UsuarioWeb) }); Console.Write(mapping.AsString()); }
private static void UnionWithPatternsAppliersHolders(IPatternsAppliersHolder source, EmptyPatternsAppliersHolder destination) { UnionWithAppliersCollection(source.RootClass, destination.RootClass); UnionWithAppliersCollection(source.JoinedSubclass, destination.JoinedSubclass); UnionWithAppliersCollection(source.Subclass, destination.Subclass); UnionWithAppliersCollection(source.UnionSubclass, destination.UnionSubclass); UnionWithAppliersCollection(source.Component, destination.Component); UnionWithAppliersCollection(source.ComponentProperty, destination.ComponentProperty); UnionWithAppliersCollection(source.ComponentPropertyPath, destination.ComponentPropertyPath); UnionWithAppliersCollection(source.Poid, destination.Poid); UnionWithAppliersCollection(source.Version, destination.Version); UnionWithAppliersCollection(source.Property, destination.Property); UnionWithAppliersCollection(source.PropertyPath, destination.PropertyPath); UnionWithAppliersCollection(source.ManyToOne, destination.ManyToOne); UnionWithAppliersCollection(source.ManyToOnePath, destination.ManyToOnePath); UnionWithAppliersCollection(source.OneToOne, destination.OneToOne); UnionWithAppliersCollection(source.OneToOnePath, destination.OneToOnePath); UnionWithAppliersCollection(source.Any, destination.Any); UnionWithAppliersCollection(source.AnyPath, destination.AnyPath); UnionWithAppliersCollection(source.Collection, destination.Collection); UnionWithAppliersCollection(source.CollectionPath, destination.CollectionPath); UnionWithAppliersCollection(source.Bag, destination.Bag); UnionWithAppliersCollection(source.BagPath, destination.BagPath); UnionWithAppliersCollection(source.List, destination.List); UnionWithAppliersCollection(source.ListPath, destination.ListPath); UnionWithAppliersCollection(source.Set, destination.Set); UnionWithAppliersCollection(source.SetPath, destination.SetPath); UnionWithAppliersCollection(source.Map, destination.Map); UnionWithAppliersCollection(source.MapPath, destination.MapPath); UnionWithAppliersCollection(source.ComponentParent, destination.ComponentParent); UnionWithAppliersCollection(source.ManyToMany, destination.ManyToMany); UnionWithAppliersCollection(source.ManyToManyPath, destination.ManyToManyPath); UnionWithAppliersCollection(source.Element, destination.Element); UnionWithAppliersCollection(source.ElementPath, destination.ElementPath); UnionWithAppliersCollection(source.OneToMany, destination.OneToMany); UnionWithAppliersCollection(source.OneToManyPath, destination.OneToManyPath); UnionWithAppliersCollection(source.MapKeyManyToMany, destination.MapKeyManyToMany); UnionWithAppliersCollection(source.MapKeyManyToManyPath, destination.MapKeyManyToManyPath); UnionWithAppliersCollection(source.MapKey, destination.MapKey); UnionWithAppliersCollection(source.MapKeyPath, destination.MapKeyPath); }
/// <summary> /// Union tow instances of <see cref="IPatternsAppliersHolder"/>. /// </summary> /// <param name="first">The main <see cref="IPatternsAppliersHolder"/> to union.</param> /// <param name="second">The second <see cref="IPatternsAppliersHolder"/> to union.</param> /// <returns>A new instance of <see cref="IPatternsAppliersHolder"/> with the result of union.</returns> /// <remarks> /// The rules of this methods are the same of <see cref="UnionWith{TSubject, TApplyTo}"/>. /// The result does not contains duplicated appliers. /// When an applier with the same type-name exists in both side the instance contained in <paramref name="second"/> will be returned. /// </remarks> public static IPatternsAppliersHolder UnionWith(this IPatternsAppliersHolder first, IPatternsAppliersHolder second) { if (first == null) { throw new ArgumentNullException("first"); } var result = new EmptyPatternsAppliersHolder(); UnionWithPatternsAppliersHolders(first, result); if (second != null) { UnionWithPatternsAppliersHolders(second, result); } return(result); }
public HbmMapping GetMapping() { #region Initialize ConfORM var orm = new ObjectRelationalMapper(); IPatternsAppliersHolder patternsAppliers = (new SafePropertyAccessorPack()) .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new CoolTablesNamingPack(orm)) .Merge(new CoolColumnsNamingPack(orm)) .Merge(new TablePerClassPack()) .Merge(new UseNoLazyForNoProxablePack()) // <== Lazy false when the class is not proxable .Merge(new ConfOrm.Shop.CoolNaming.UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm)) .Merge(new UseCurrencyForDecimalApplier()) .Merge(new DatePropertyByNameApplier()) .Merge(new MsSQL2008DateTimeApplier()); orm.Patterns.PoidStrategies.Add(new HighLowPoidPattern(new { max_lo = 100 })); var mapper = new Mapper(orm, patternsAppliers); var domainEntities = typeof(Entity) .Assembly.GetTypes() .Where(t => (typeof(AbstractEntity <int>).IsAssignableFrom(t) || typeof(AbstractEntity <Guid>).IsAssignableFrom(t)) && !t.IsGenericType) .ToList(); IEnumerable <Type> tablePerClassEntities = typeof(Entity) .Assembly.GetTypes().Where(t => IsRootEntity(t) && !tablePerClassHierarchy.Contains(t) && !tablePerConcreteClass.Contains(t)).ToList(); // Mappings orm.TablePerClass(tablePerClassEntities); orm.TablePerClassHierarchy(tablePerClassHierarchy); orm.TablePerConcreteClass(tablePerConcreteClass); #endregion ConfOrmMapping(orm, mapper); return(mapper.CompileMappingFor(domainEntities)); }
private Mapper GetMapper() { #region Initialize ConfORM //var inflector = new EnglishInflector(); var orm = new ObjectRelationalMapper(); IPatternsAppliersHolder patternsAppliers = (new SafePropertyAccessorPack()) .Merge(new SafePoidPack()) .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new CoolTablesNamingPack(orm)) //.Merge(new PluralizedTablesPack(orm, inflector)) .Merge(new CoolColumnsNamingPack(orm)) //.UnionWith(new ConfOrm.Shop.InflectorNaming.CollectionOfElementsColumnApplier(orm, inflector)) .Merge(new PolymorphismPack(orm)) .Merge(new TablePerClassPack()) .Merge(new UseNoLazyForNoProxablePack()) // <== Lazy false when the class is not proxable .Merge(new ConfOrm.Shop.CoolNaming.UnidirectionalOneToManyMultipleCollectionsKeyColumnApplier(orm)) .Merge(new UseCurrencyForDecimalApplier()) .Merge(new DatePropertyByNameApplier()) .Merge(new MsSQL2008DateTimeApplier()); orm.Patterns.PoidStrategies.Add(new HighLowPoidPattern(new { max_lo = 100 })); var mapper = new Mapper(orm, patternsAppliers); IEnumerable <Type> tablePerClassEntities = typeof(Entity) .Assembly.GetTypes().Where(t => IsRootEntity(t) && !tablePerClassHierarchy.Contains(t) && !tablePerConcreteClass.Contains(t)).ToList(); // Mappings orm.AddToDomain(typeof(Entity).Assembly.GetTypes()); orm.TablePerClass(tablePerClassEntities); orm.TablePerClassHierarchy(tablePerClassHierarchy); orm.TablePerConcreteClass(tablePerConcreteClass); #endregion ConfOrmMapping(orm, mapper); return(mapper); }
public HbmMapping GenerateMappigs() { var orm = new ObjectRelationalMapper(); orm.Patterns.PoidStrategies.Add(new NativePoidPattern()); //// map .NET4 ISet<T> as a NHibernate's set orm.Patterns.Sets.Add(new UseSetWhenGenericCollectionPattern()); var englishInflector = new EnglishInflector(); IPatternsAppliersHolder patternsAppliers = (new SafePropertyAccessorPack()) .Merge(new ClassPluralizedTableApplier(englishInflector)) .Merge(new DiscriminatorValueAsEnumValuePack <ChildA, Types>(orm)) .Merge(new DiscriminatorValueAsEnumValuePack <ChildB, Types>(orm)) .Merge(new CoolPatternsAppliersHolder(orm)); IEnumerable <Type> allPersistEntities = GetDomainEntities(); IEnumerable <Type> roots = allPersistEntities.Where(t => t.IsAbstract && t.InheritedFromBaseEntity()); IEnumerable <Type> hierarchyEntities = allPersistEntities.Where(t => typeof(IHierarchyEntity).IsAssignableFrom(t)); IEnumerable <Type> separateEntities = allPersistEntities.Except(roots).Except(hierarchyEntities); orm.TablePerConcreteClass(separateEntities); var hierarchyRoots = hierarchyEntities.Where(t => t.IsAbstract && t.InheritedFromBaseEntity()); orm.TablePerClassHierarchy(hierarchyRoots); orm.Cascade <ChildA, Container>(CascadeOn.Persist | CascadeOn.Merge); orm.Cascade <Container, ChildA>(CascadeOn.Persist); orm.Cascade <ChildB, Container>(CascadeOn.Persist | CascadeOn.Merge); orm.Cascade <Container, ChildB>(CascadeOn.Persist); var mapper = new Mapper(orm, patternsAppliers); HbmMapping mapping = mapper.CompileMappingFor(allPersistEntities); File.WriteAllText(@"c:\Test\mappings.xml", Serialize(mapping)); // сохраняем маппинги в файл. return(mapping); }
public void ExclusionDemo() { var orm = new ObjectRelationalMapper(); orm.Patterns.Poids.Add(new MyPoidProperty()); // <== recognize the property representing the POID IPatternsAppliersHolder patternsAppliers = (new CoolPatternsAppliersHolder(orm)) .UnionWith(new MyTablesAndColumnsNamingPack()); // <=== Note the usage of UnionWith instead Merge var mapper = new Mapper(orm, patternsAppliers); // The strategy to represent classes is not important orm.TablePerClass <PorBoxEO>(); orm.TablePerClass <PorEO>(); // Show the mapping to the console HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(PorEO), typeof(PorBoxEO) }); Console.Write(mapping.AsString()); }
public DearDbaDomainMapper() { orm = new ObjectRelationalMapper(); // Remove one of not required patterns orm.Patterns.ManyToOneRelations.Remove( orm.Patterns.ManyToOneRelations.Single(p => p.GetType() == typeof(OneToOneUnidirectionalToManyToOnePattern))); orm.Patterns.PoidStrategies.Add(new NativePoidPattern()); IPatternsAppliersHolder patternsAppliers = (new SafePropertyAccessorPack()) .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new DearDbaTablesAndColumnsNamingPack(orm, new EnglishInflector())) .Merge(new TablePerClassPack()) .Merge(new DatePropertyByNameApplier()) .Merge(new MsSQL2008DateTimeApplier()); patternsAppliers.Merge(new DatePropertyByNameApplier()).Merge(new MsSQL2008DateTimeApplier()); mapper = new Mapper(orm, patternsAppliers); }
public void ApplyFieldAccessor_AsDefaultAccess_WithMappingDocumentForEachClass() { var orm = new ObjectRelationalMapper(); IPatternsAppliersHolder patternsAppliers = (new AccessToPropertyWhereNoFieldPack()) // <== in this case I'll apply a default-access for the whole mapping, but there are cases where the field does not exists (let ConfORM check it ;) ) .Merge(new OneToOneRelationPack(orm)) .Merge(new BidirectionalManyToManyRelationPack(orm)) .Merge(new BidirectionalOneToManyRelationPack(orm)) .Merge(new DiscriminatorValueAsClassNamePack(orm)) .Merge(new CoolTablesAndColumnsNamingPack(orm)) .Merge(new TablePerClassPack()); var mapper = new Mapper(orm, patternsAppliers); orm.TablePerClass <Person>(); var mappings = mapper.CompileMappingForEach(new[] { typeof(Person) }).WithDefaultAccessor("field.camelcase"); foreach (var mapping in mappings) { Console.Write(mapping.AsString()); } }
/// <summary> /// Add or Replace the <paramref name="applier"/> to the correspondig collection inside the <paramref name="source"/>. /// </summary> /// <typeparam name="TSubject">The subject of the pattern.</typeparam> /// <typeparam name="TApplyTo">The target of the applier.</typeparam> /// <param name="source">An instance of <see cref="IPatternsAppliersHolder"/>>.</param> /// <param name="applier">The instance of the applier to add.</param> /// <returns>The <paramref name="source"/> instance (to chain 'union')</returns> /// <remarks> /// The Replace action is performed removing all appliers with the same type-name, where exists, and then adding the new applier. /// This method is usefull when you want override a behaviour of an existing applier in an existing <see cref="IPatternsAppliersHolder"/>. /// </remarks> public static IPatternsAppliersHolder UnionWith <TSubject, TApplyTo>(this IPatternsAppliersHolder source, IPatternApplier <TSubject, TApplyTo> applier) { if (source == null) { throw new ArgumentNullException("source"); } if (applier == null) { return(source); } var patternsAppliersCollection = GetCollectionPropertyOf <TSubject, TApplyTo>(source); if (patternsAppliersCollection != null) { PerformUnionWith(patternsAppliersCollection, applier); } else { throw new ArgumentOutOfRangeException("applier", string.Format(NotSupportedApplierExceptionMessageTemplate, typeof(TSubject).FullName, typeof(TApplyTo).FullName)); } return(source); }
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()); }
private static ICollection <IPatternApplier <TSubject, TApplyTo> > GetCollectionPropertyOf <TSubject, TApplyTo>(IPatternsAppliersHolder source) { var property = typeof(IPatternsAppliersHolder).GetFirstPropertyOfType(typeof(ICollection <IPatternApplier <TSubject, TApplyTo> >)); if (property != null) { return((ICollection <IPatternApplier <TSubject, TApplyTo> >)(((PropertyInfo)property).GetValue(source, null))); } return(null); }
public void WhenSourceIsNullThenThrow() { IPatternsAppliersHolder source = null; Executing.This(() => source.Merge(null)).Should().Throw <ArgumentNullException>(); }
public void WhenApplier_TypeUnionSubclassAttributesMapper_ThenAddToItsCollection() { IPatternsAppliersHolder source = GetPatternsAppliersHolderWithApplierAdded <Type, IUnionSubclassAttributesMapper>(); source.UnionSubclass.Count.Should().Be(1); }
public void WhenApplier_PropertyPathPropertyMapper_ThenAddToItsCollection() { IPatternsAppliersHolder source = GetPatternsAppliersHolderWithApplierAdded <PropertyPath, IPropertyMapper>(); source.PropertyPath.Count.Should().Be(1); }
public void WhenSourceIsNullThenThrow() { IPatternsAppliersHolder source = null; ActionAssert.Throws <ArgumentNullException>(() => source.UnionWith(null)); }
public void WhenApplier_MemberInfoManyToOneMapper_ThenAddToItsCollection() { IPatternsAppliersHolder source = GetPatternsAppliersHolderWithApplierAdded <MemberInfo, IManyToOneMapper>(); source.ManyToOne.Count.Should().Be(1); }
public void WhenApplier_MemberInfoCollectionPropertiesMapper_ThenAddToItsCollection() { IPatternsAppliersHolder source = GetPatternsAppliersHolderWithApplierAdded <MemberInfo, ICollectionPropertiesMapper>(); source.Collection.Count.Should().Be(1); }
public void WhenSourceIsNullThenThrow() { IPatternsAppliersHolder source = null; ActionAssert.Throws <ArgumentNullException>(() => source.Merge <PropertyPath, IPropertyMapper>(null)); }
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 WhenSourceIsNullThenThrow() { IPatternsAppliersHolder source = null; Executing.This(() => source.UnionWith <PropertyPath, IPropertyMapper>(null)).Should().Throw <ArgumentNullException>(); }