当前位置: 首页>>代码示例>>C#>>正文


C# Mapper.CompileMappingFor方法代码示例

本文整理汇总了C#中Mapper.CompileMappingFor方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.CompileMappingFor方法的具体用法?C# Mapper.CompileMappingFor怎么用?C# Mapper.CompileMappingFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mapper的用法示例。


在下文中一共展示了Mapper.CompileMappingFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ComposingPatternsAppliersPacksUsingInflector

        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());
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:30,代码来源:CompositionDemo.cs

示例2: GetMockedDomainInspector

        public void WhenCustomizeNestedComponentParentAccessThroughCollectionThenApplyCustomizationToMappingForCompositeElement()
        {
            Mock<IDomainInspector> orm = GetMockedDomainInspector();

            var domainInspector = orm.Object;
            var mapper = new Mapper(domainInspector);

            mapper.Class<MyClass>(
                ca =>
                ca.Bag(mycomponent => mycomponent.Components, x => { },
                       cer =>
                       cer.Component(
                       	c =>
                       	c.Component(mycomponent => mycomponent.Component,
                       	            ce => ce.Parent(mync => mync.Parent, pa => pa.Access(Accessor.Field))))));

            HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("MyClass"));
            var hbmBag = (HbmBag)rc.Properties.First(p => p.Name == "Components");
            var hbmCompositeElement = (HbmCompositeElement)hbmBag.ElementRelationship;
            var hbmNestedCompositeElement = (HbmNestedCompositeElement)hbmCompositeElement.Properties.First(p => p.Name == "Component");
            hbmNestedCompositeElement.Parent.name.Should().Be("Parent");
            hbmNestedCompositeElement.Parent.access.Should().Be("field.camelcase-underscore");
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:25,代码来源:NestedComponentAttributesCustomizationTest.cs

示例3: ExecuteCustomDelegatedApplier

        public void ExecuteCustomDelegatedApplier()
        {
            var orm = new Mock<IDomainInspector>();
            orm.Setup(m => m.IsEntity(It.IsAny<Type>())).Returns(true);
            orm.Setup(m => m.IsRootEntity(It.IsAny<Type>())).Returns(true);
            orm.Setup(m => m.IsTablePerClass(It.IsAny<Type>())).Returns(true);
            orm.Setup(m => m.IsPersistentId(It.Is<MemberInfo>(mi => mi.Name == "Id"))).Returns(true);
            orm.Setup(m => m.IsPersistentProperty(It.Is<MemberInfo>(mi => mi.Name != "Id"))).Returns(true);

            var mapper = new Mapper(orm.Object);
            mapper.AddPropertyPattern(mi => mi.GetPropertyOrFieldType() == typeof(DateTime) && (mi.Name.StartsWith("Date") || mi.Name.EndsWith("Date")),
                                      pm => pm.Type(NHibernateUtil.Date));
            var mapping = mapper.CompileMappingFor(new[] {typeof (MyClass)});

            var hbmClass = mapping.RootClasses.Single();

            var hbmProp = (HbmProperty) hbmClass.Properties.First(p => p.Name == "Date");
            hbmProp.Type.name.Should().Be.EqualTo("Date");

            hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "DateOfMeeting");
            hbmProp.Type.name.Should().Be.EqualTo("Date");

            hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "MeetingDate");
            hbmProp.Type.name.Should().Be.EqualTo("Date");

            hbmProp = (HbmProperty)hbmClass.Properties.First(p => p.Name == "StartAt");
            hbmProp.Type.Should().Be.Null();
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:28,代码来源:CustomPropertyPatternApplierTest.cs

示例4: CallCustomizerOnCompositeElementsProperties

        public void CallCustomizerOnCompositeElementsProperties()
        {
            Mock<IDomainInspector> orm = GetMockedDomainInspector();
            var mapper = new Mapper(orm.Object);
            bool simplePropertyCalled = false;
            bool manyToOneCalled = false;
            bool reSimplePropertyCalled = false;
            bool reManyToOneCalled = false;

            mapper.Customize<MyComponent>(x =>
            {
                x.Property(mc => mc.Simple, pm => simplePropertyCalled = true);
                x.ManyToOne(mc => mc.ManyToOne, pm => manyToOneCalled = true);
            });
            mapper.Customize<MyNestedComponent>(x =>
            {
                x.Property(mc => mc.ReSimple, pm => reSimplePropertyCalled = true);
                x.ManyToOne(mc => mc.ReManyToOne, pm => reManyToOneCalled = true);
            });

            mapper.CompileMappingFor(new[] { typeof(MyClass) });
            simplePropertyCalled.Should().Be.True();
            manyToOneCalled.Should().Be.True();
            reSimplePropertyCalled.Should().Be.True();
            reManyToOneCalled.Should().Be.True();
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:26,代码来源:CustomizerCallingOnCompositeElementTest.cs

示例5: ComposingPatternsAppliersPacks

        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());
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:60,代码来源:Demo.cs

示例6: GetMapping

 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);
 }
开发者ID:dinhqbao,项目名称:NHibernate-3.0-Cookbook,代码行数:29,代码来源:Program.cs

示例7: GetMapings

        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;
        }
开发者ID:RoyRV,项目名称:Training.MVC.Net,代码行数:32,代码来源:MapConfiguration.cs

示例8: InitMappings

        /// <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();
        }
开发者ID:GunioRobot,项目名称:vlko,代码行数:30,代码来源:DBInit.cs

示例9: WhenCustomizedAndSpecifiedThenSetDifferentConfigurationForSameComponent

        public void WhenCustomizedAndSpecifiedThenSetDifferentConfigurationForSameComponent()
        {
            Mock<IDomainInspector> orm = GetMockedDomainInspector();

            var domainInspector = orm.Object;
            var mapper = new Mapper(domainInspector);
            mapper.Customize<Name>(name =>
                {
                    name.Property(np => np.First, pm => pm.Length(20));
                    name.Property(np => np.Last, pm => pm.Length(35));
                });

            mapper.Class<Person>(c =>
                {
                    c.Component(p => p.RealName, cname => cname.Property(cnp => cnp.Last, pm => pm.Length(50)));
                    c.Component(p => p.Aka, cname => cname.Property(cnp => cnp.First, pm => pm.Length(50)));
                });

            HbmMapping mapping = mapper.CompileMappingFor(new[] { typeof(Person) });

            HbmClass rc = mapping.RootClasses.First(r => r.Name.Contains("Person"));
            var hbmRealName = (HbmComponent)rc.Properties.First(p => p.Name == "RealName");
            var hbmAka = (HbmComponent)rc.Properties.First(p => p.Name == "Aka");
            hbmRealName.Properties.OfType<HbmProperty>().Select(p => p.length).Should().Have.SameValuesAs("20", "50");
            hbmAka.Properties.OfType<HbmProperty>().Select(p => p.length).Should().Have.SameValuesAs("50", "35");
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:26,代码来源:ComponentDoublePropertyTest.cs

示例10: DefiningAndCustomizingVersionThroughBaseImplementation

        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());
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:34,代码来源:Demo.cs

示例11: CreateMapping

        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;
        }
开发者ID:henleygao,项目名称:PMMS,代码行数:27,代码来源:MappingFactory.cs

示例12: ComposingPatternsAppliersPacks

        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());
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:35,代码来源:CompositionDemo.cs

示例13: MapDocShouldSetDefaultAssemblyWhenTypesComesFromSameAssembly

        public void MapDocShouldSetDefaultAssemblyWhenTypesComesFromSameAssembly()
        {
            var di = new Mock<IDomainInspector>();
            var mapper = new Mapper(di.Object);

            var mappings = mapper.CompileMappingFor(new[] { typeof(MyEntity), typeof(AEntity) });
            mappings.assembly.Should().Be.EqualTo(typeof (MyEntity).Assembly.GetName().Name);
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:8,代码来源:DefaultAssemblyAndNamespaceTest.cs

示例14: MapDocShouldNotSetDefaultNamespaceWhenTypesComesFromVariousNamespaces

        public void MapDocShouldNotSetDefaultNamespaceWhenTypesComesFromVariousNamespaces()
        {
            var di = new Mock<IDomainInspector>();
            var mapper = new Mapper(di.Object);

            var mappings = mapper.CompileMappingFor(new[] { typeof(MyEntity), typeof(Assert) });
            [email protected]().Be.Null();
        }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:8,代码来源:DefaultAssemblyAndNamespaceTest.cs

示例15: WhenCircularReferenceShouldNotMatch

 public void WhenCircularReferenceShouldNotMatch()
 {
     var orm = GetMockedDomainInspector();
     var mapper = new Mapper(orm.Object);
     var mappings = mapper.CompileMappingFor(new[] { typeof(Person) });
     var hbmPersonFriends = mappings.RootClasses.First(rc => rc.Name.Contains("Person")).Properties.OfType<HbmBag>().Single();
     hbmPersonFriends.Table.Should().Be.Null();
 }
开发者ID:alvarezdaniel,项目名称:conformando-nhibernate,代码行数:8,代码来源:BidirectionalManyToManyTableTest.cs


注:本文中的Mapper.CompileMappingFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。