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


C# ByCode.ConventionModelMapper类代码示例

本文整理汇总了C#中NHibernate.Mapping.ByCode.ConventionModelMapper的典型用法代码示例。如果您正苦于以下问题:C# ConventionModelMapper类的具体用法?C# ConventionModelMapper怎么用?C# ConventionModelMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GetIdentityMappings

        /// <summary>
        /// Gets a mapping that can be used with NHibernate.
        /// </summary>
        /// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
        /// <returns></returns>
        public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
        {
            var baseEntityToIgnore = new[] { 
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>), 
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>), 
            };

            var allEntities = new List<System.Type> { 
                typeof(ApplicationTenant),
                typeof(IdentityUser),                 
                typeof(IdentityRole), 
                typeof(IdentityUserLogin), 
                typeof(IdentityUserClaim),
            };
            allEntities.AddRange(additionalTypes);

            var mapper = new ConventionModelMapper();
            DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
            mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));

            mapper.AddMapping<IdentityUserMap>();
            mapper.AddMapping<IdentityRoleMap>();
            mapper.AddMapping<IdentityUserClaimMap>();
            mapper.AddMapping<ApplicationTenantMap>();

            return mapper.CompileMappingFor(allEntities);
        }
开发者ID:dags20,项目名称:NHibernate.AspNet.Identity.MultiTenant,代码行数:32,代码来源:MappingHelper.cs

示例2: NHibernateHelper

        static NHibernateHelper()
        {
            try
            {
                cfg = new Configuration();
                cfg.Configure("NHibernateQueryModelConfiguration.xml");

                var mapper = new ConventionModelMapper();
                //mapper.IsEntity((t, declared) => t.Namespace.StartsWith("Sample.QueryModel") || );

                mapper.AfterMapClass += (inspector, type, classCustomizer) =>
                {
                    classCustomizer.Lazy(false);
                    //classCustomizer.Id(m => m.Generator(new GuidGeneratorDef()));
                };
                var mapping = mapper.CompileMappingFor(
                    Assembly.Load("Sample.QueryModel").GetExportedTypes()
                    .Union(new Type[] {typeof(Version)}));
                var allmapping = mapping.AsString();

                cfg.AddDeserializedMapping(mapping, "AutoModel");
                _sessionFactory = cfg.BuildSessionFactory();
 
            }
            catch (Exception ex)
            {
                throw ex;
            }
         
        }
开发者ID:AGiorgetti,项目名称:Prxm.Cqrs,代码行数:30,代码来源:NHibernateHelper.cs

示例3: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ConventionModelMapper();
			// Working Example
			//mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap => { }, rel => rel.ManyToAny<int>(meta =>
			//                                                                                      {
			//                                                                                        meta.MetaValue(1, typeof (Cat));
			//                                                                                        meta.MetaValue(2, typeof (Dog));
			//                                                                                      })));

			// User needs
			mapper.Class<Toy>(rc => rc.Set(x => x.Animals, cmap =>
																										 {
																											 cmap.Table("Animals_Toys");
																											 cmap.Key(km => km.Column("Cat_Id"));
																										 }, rel => rel.ManyToAny<int>(meta =>
																																									{
																																										meta.MetaValue(1, typeof(Cat));
																																										meta.MetaValue(2, typeof(Dog));
																																										meta.Columns(cid =>
																																																 {
																																																	 cid.Name("Animal_Id");
																																																	 cid.NotNullable(true);
																																																 }, ctype =>
																																																		{
																																																			ctype.Name("Animal_Type");
																																																			ctype.NotNullable(true);
																																																		});
																																									})));
			var mappings = mapper.CompileMappingFor(new[] { typeof(Cat), typeof(Dog), typeof(Toy) });
			//Console.WriteLine(mappings.AsString()); // <=== uncomment this line to see the XML mapping
			return mappings;
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:33,代码来源:SampleTest.cs

示例4: MappingEngine

 /// <summary>
 /// Initializes a new instance of the <see cref="MappingEngine"/> class
 /// </summary>
 /// <param name="rootConfig">The root configuration</param>
 /// <param name="nhConfig">The current NH configuration</param>
 /// <param name="modelMapper">The model mapper</param>
 public MappingEngine(FirehawkConfig rootConfig, Configuration nhConfig, ConventionModelMapper modelMapper)
 {
     this.rootConfig = rootConfig;
     this.nhConfig = nhConfig;
     this.modelMapper = modelMapper;
     this.namingEngine = new NamingEngine(rootConfig.NamingConventionsConfig);
 }
开发者ID:HomeroThompson,项目名称:firehawk,代码行数:13,代码来源:MappingEngine.cs

示例5: Main

        static void Main(string[] args)
        {
            SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);

            var mapper = new ConventionModelMapper();

            mapper.Class<SomeAreaClass>(c =>
            {
                c.Property(x => x.Area, m =>
                {
                    m.Type<MsSql2008GeographyType>();
                    m.NotNullable(true);
                });
            });

            var cfg = new Configuration()

                .DataBaseIntegration(db =>
                {
                    db.ConnectionString = "YourConnectionString";
                    db.Dialect<MsSql2012GeographyDialect>();
                });

            cfg
                .AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());

            cfg
                .AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg));

            new SchemaExport(cfg).Execute(false, true, false);
        }
开发者ID:danielcweber,项目名称:NHibernateSpatialBug,代码行数:31,代码来源:Program.cs

示例6: ExplicitMapping

		static void ExplicitMapping(ConventionModelMapper mapper)
		{
			mapper.Class<Master>(x =>
			{
				x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
				x.Set(y => y.Options, y =>
				{
					y.Key(z => z.Column("master_id"));
					y.Table("master_option");
				}, y =>
				{
					y.ManyToMany(z =>
					{
						z.Column("option_id");
					});
				});
			});

			mapper.Class<Option>(x =>
			{
				x.Id(y => y.Id, y => y.Generator(Generators.HighLow));
				x.Set(y => y.Masters, y =>
				{
					y.Key(z => z.Column("option_id"));
					y.Table("master_option");
					y.Inverse(true);
				}, y =>
				{
					y.ManyToMany(z =>
					{
						z.Column("master_id");
					});
				});
			});
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.NHibernateConventions,代码行数:35,代码来源:Program.cs

示例7: TestFixtureSetUp

 public void TestFixtureSetUp()
 {
     configuration = new Configuration();
     configuration.SessionFactory()
                  .Integrate.Using<SQLiteDialect>()
                  .Connected.Using("Data source=testdb")
                  .AutoQuoteKeywords()
                  .LogSqlInConsole()
                  .EnableLogFormattedSql();
     var mapper = new ConventionModelMapper();
     mapper.Class<Foo>(cm => { });
     mapper.Class<Bar>(cm => { });
     CustomizeMapping(mapper);
     var mappingDocument = mapper.CompileMappingForAllExplicitlyAddedEntities();
     new XmlSerializer(typeof(HbmMapping)).Serialize(Console.Out, mappingDocument);
     configuration.AddDeserializedMapping(mappingDocument, "Mappings");
     new SchemaExport(configuration).Create(true, true);
     sessionFactory = configuration.BuildSessionFactory();
     using (var session = sessionFactory.OpenSession())
     using (var tx = session.BeginTransaction())
     {
         var foo = new Foo { Bars = CreateCollection() };
         foo.Bars.Add(new Bar { Data = 1 });
         foo.Bars.Add(new Bar { Data = 2 });
         id = session.Save(foo);
         tx.Commit();
     }
     sessionFactory.Statistics.IsStatisticsEnabled = true;
 }
开发者ID:polyzois,项目名称:NHibernate.Diegose,代码行数:29,代码来源:QueryableCollectionsFixture.cs

示例8: ConventionsMapper

        public ConventionsMapper()
        {
            this.conventionModelMapper = new ConventionModelMapper();

            var baseEntityType = typeof(Entity);
            this.conventionModelMapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
            this.conventionModelMapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
            this.conventionModelMapper.Class<Entity>(map => {
                                                     	map.Id(x => x.Id, m => m.Generator(Generators.Identity));
                                                     	map.Id(x => x.Id, m => m.Column("id"));
                                                     	map.Version(x => x.Version, m => m.Generated(VersionGeneration.Always));
                                                     	map.Version(x => x.Version, m => m.Column("version"));
                                                     });

            this.conventionModelMapper.BeforeMapProperty += (insp, prop, map) => map.Column(prop.LocalMember.Name);

            this.conventionModelMapper.BeforeMapManyToOne += (insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
            this.conventionModelMapper.BeforeMapManyToOne += (insp, prop, map) => map.Cascade(Cascade.Persist);

            this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Table(prop.GetContainerEntity(insp).Name + prop.GetRootMember().Name);
            this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
            this.conventionModelMapper.BeforeMapBag += (insp, prop, map) => map.Cascade(Cascade.All);

            this.conventionModelMapper.BeforeMapClass += (insp, prop, map) => map.Table(prop.Name);

            this.conventionModelMapper.AddMappings(typeof(RestaurantMappings).Assembly.GetTypes());
            this.mapping = this.conventionModelMapper.CompileMappingFor(baseEntityType.Assembly.GetExportedTypes().Where(t => t.Namespace != null && t.Namespace.EndsWith("Entities")));
        }
开发者ID:garunski,项目名称:Lunchage,代码行数:28,代码来源:ConventionsMapper.cs

示例9: Initialize

        public static Configuration Initialize()
        {
            INHibernateConfigurationCache cache = new NHibernateConfigurationFileCache();

            var mappingAssemblies = new[] {
                typeof(ActionConfirmation<>).Assembly.GetName().Name
            };

            var configuration = cache.LoadConfiguration(CONFIG_CACHE_KEY, null, mappingAssemblies);

            if (configuration == null) {
                configuration = new Configuration();

                configuration
                    .Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
                    .DataBaseIntegration(db => {
                        db.ConnectionStringName = "DonSharpLiteConnectionString";
                        db.Dialect<MsSql2008Dialect>();
                    })
                    .AddAssembly(typeof(ActionConfirmation<>).Assembly)
                    .CurrentSessionContext<LazySessionContext>();

                var mapper = new ConventionModelMapper();
                mapper.WithConventions(configuration);

                cache.SaveConfiguration(CONFIG_CACHE_KEY, configuration);
            }

            return configuration;
        }
开发者ID:antgerasim,项目名称:DonSharpArchitecture,代码行数:30,代码来源:NHibernateInitializer.cs

示例10: Configure

        public static void Configure(ISessionStorage storage)
        {
            var baseEntityToIgnore = new[] { 
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<int>), 
                typeof(NHibernate.AspNet.Identity.DomainModel.EntityWithTypedId<string>), 
            };

            var allEntities = new[] { 
                typeof(IdentityUser), 
                typeof(ApplicationUser), 
                typeof(IdentityRole), 
                typeof(IdentityUserLogin), 
                typeof(IdentityUserClaim), 
            };

            var mapper = new ConventionModelMapper();
            DefineBaseClass(mapper, baseEntityToIgnore);
            mapper.IsComponent((type, declared) => typeof(NHibernate.AspNet.Identity.DomainModel.ValueObject).IsAssignableFrom(type));

            mapper.AddMapping<IdentityUserMap>();
            mapper.AddMapping<IdentityRoleMap>();
            mapper.AddMapping<IdentityUserClaimMap>();

            var mapping = mapper.CompileMappingFor(allEntities);
            System.Diagnostics.Debug.WriteLine(mapping.AsString());

            var configuration = NHibernateSession.Init(storage, mapping);
            BuildSchema(configuration);
        }
开发者ID:robocik,项目名称:NHibernate.AspNet.Identity,代码行数:29,代码来源:DataConfig.cs

示例11: GetIdentityMappings

        /// <summary>
        /// Gets a mapping that can be used with NHibernate.
        /// </summary>
        /// <param name="additionalTypes">Additional Types that are to be added to the mapping, this is useful for adding your ApplicationUser class</param>
        /// <returns></returns>
        public static HbmMapping GetIdentityMappings(System.Type[] additionalTypes)
        {
            var baseEntityToIgnore = new[]
            {
                typeof(EntityWithTypedId<int>),
                typeof(EntityWithTypedId<string>)
            };

            // Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
            var allEntities = new List<System.Type> {
                typeof(IdentityUser),
                typeof(IdentityRole),
                typeof(IdentityUserLogin),
                typeof(IdentityUserClaim),
            };
            allEntities.AddRange(additionalTypes);

            var mapper = new ConventionModelMapper();
            DefineBaseClass(mapper, baseEntityToIgnore.ToArray());
            mapper.IsComponent((type, declared) => typeof(ValueObject).IsAssignableFrom(type));

               // Modified for NS: PIMS.Infrastructure.NHibernate.NHAspNetIdentity
            mapper.AddMapping<IdentityUserMap>();
            mapper.AddMapping<IdentityRoleMap>();
            mapper.AddMapping<IdentityUserClaimMap>();

            return mapper.CompileMappingFor(allEntities);
        }
开发者ID:RichardPAsch,项目名称:PIMS,代码行数:33,代码来源:MappingHelper.cs

示例12: CustomizeMapping

 protected override void CustomizeMapping(ConventionModelMapper mapper)
 {
     mapper.Class<Foo>(cm => cm.List(x => x.Bars, bpm =>
                                                  {
                                                      bpm.Cascade(Cascade.All);
                                                      bpm.Type<PersistentQueryableListType<Bar>>();
                                                  }));
 }
开发者ID:polyzois,项目名称:NHibernate.Diegose,代码行数:8,代码来源:ListFixture.cs

示例13: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ConventionModelMapper();
			mapper.IsTablePerClass((type, declared) => false);
			mapper.IsTablePerClassHierarchy((type, declared) => true);
			var mappings = mapper.CompileMappingFor(new[] {typeof (Animal), typeof (Reptile), typeof (Mammal), typeof (Lizard), typeof (Dog), typeof (Cat)});
			return mappings;
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:8,代码来源:Fixture.cs

示例14: WhenPoidNoSetterThenApplyNosetter

		public void WhenPoidNoSetterThenApplyNosetter()
		{
			var mapper = new ConventionModelMapper();
			mapper.Class<MyClass>(x => x.Id(mc=> mc.Id));
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });

			var hbmClass = hbmMapping.RootClasses[0];
			hbmClass.Id.access.Should().Be("nosetter.camelcase-underscore");
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:9,代码来源:SafePoidTests.cs

示例15: WhenAutoPropertyNoAccessor

		public void WhenAutoPropertyNoAccessor()
		{
			var mapper = new ConventionModelMapper();
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });

			var hbmClass = hbmMapping.RootClasses[0];
			var hbmProperty = hbmClass.Properties.Single(x => x.Name == "AProp");
			hbmProperty.Access.Should().Be.NullOrEmpty();
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:9,代码来源:PropertyToFieldAccessorTest.cs


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