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


C# ConventionModelMapper.CompileMappingFor方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: WhenPropertyWithSameBackFieldNoMatch

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

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

示例10: WhenFieldAccessToField

		public void WhenFieldAccessToField()
		{
			var mapper = new ConventionModelMapper();
			mapper.Class<MyClass>(mc => mc.Property("aField", x => { }));
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClass) });

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

示例11: Main

		static void Main(String[] args)
		{
			var cfg = new Configuration();
			cfg.DataBaseIntegration(x =>
				{
					x.Dialect<MsSql2008Dialect>();
					x.Driver<Sql2008ClientDriver>();
					x.ConnectionString = @"Data Source=(local)\SQLEXPRESS; Initial Catalog=NHibernate; Integrated Security=SSPI";
					x.SchemaAction = SchemaAutoAction.Update;
				})
				.SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString);

			var model = new ConventionModelMapper();
			model.BeforeMapClass += (a, b, c) => { c.Lazy(false); c.Id(x => x.Generator(Generators.Identity)); };

			var mappings = model.CompileMappingFor(new Type[] { typeof(Xpto) });

			cfg.AddMapping(mappings);

			using (var sessionFactory = cfg.BuildSessionFactory())
			{
				var validation = sessionFactory
					.FluentlyValidate()
					.Entity<Xpto>(x => x.Name != "aa", "Name is empty");

				using (var session = sessionFactory.OpenSession())
				using (var tx = session.BeginTransaction())
				{
					var x = new Xpto();

					try
					{
						session.Save(x);
						session.Flush();
					}
					catch
					{
						//expected
					}

					x.Name = "aa";

					//disable all validations
					//sessionFactory.DisableFluentValidation();
					
					//disable validations over the Xpto class
					//validation.Clear<Xpto>();

					//session.Save(new Xpto());
					session.Flush();
					//should work
				}
			}
		}
开发者ID:rjperes,项目名称:DevelopmentWithADot.NHibernateFluentValidation,代码行数:54,代码来源:Program.cs

示例12: AddConventionalMapping

        static void AddConventionalMapping(Configuration cfg)
        {
            var modelMapper = new ConventionModelMapper();
            modelMapper.IsEntity((x, y) => x.IsClass == true && x.IsSealed == false && x.Namespace == typeof(Program).Namespace);
            modelMapper.BeforeMapClass += (x, y, z) => { z.Id(a => a.Generator(Generators.Identity)); z.Lazy(true); };
            modelMapper.BeforeMapManyToOne += (x, y, z) => { z.Lazy(LazyRelation.Proxy); z.NotNullable(true); };

            var mappings = modelMapper.CompileMappingFor(typeof(Program).Assembly.GetTypes().Where(x => x.IsPublic && x.IsSealed == false));

            cfg.AddMapping(mappings);
        }
开发者ID:rjperes,项目名称:NHPerformance,代码行数:11,代码来源:Program.cs

示例13: WhenClassWithoutPoidWithGeneratorThenApplyDefinedGenerator

		public void WhenClassWithoutPoidWithGeneratorThenApplyDefinedGenerator()
		{
			var mapper = new ConventionModelMapper();
			mapper.Class<MyClassWithoutPoid>(x => x.Id(null, idm=> idm.Generator(Generators.Native)));
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithoutPoid) });

			var hbmClass = hbmMapping.RootClasses[0];
			var hbmId = hbmClass.Id;
			hbmId.Should().Not.Be.Null();
			hbmId.generator.Should().Not.Be.Null();
			[email protected]().Be("native");
			hbmId.type1.Should().Be(Generators.Native.DefaultReturnType.GetNhTypeName());
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:13,代码来源:SafePoidTests.cs

示例14: WhenClassWithoutPoidNorGeeneratorThenApplyGuid

		public void WhenClassWithoutPoidNorGeeneratorThenApplyGuid()
		{
			var mapper = new ConventionModelMapper();
			mapper.Class<MyClassWithoutPoid>(x => { });
			var hbmMapping = mapper.CompileMappingFor(new[] { typeof(MyClassWithoutPoid) });

			var hbmClass = hbmMapping.RootClasses[0];
			var hbmId = hbmClass.Id;
			hbmId.Should().Not.Be.Null();
			hbmId.generator.Should().Not.Be.Null();
			[email protected]().Be("guid");
			hbmId.type1.Should().Be("Guid");
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:13,代码来源:SafePoidTests.cs

示例15: GetMappings

		protected override HbmMapping GetMappings()
		{
			var mapper = new ConventionModelMapper();
			mapper.BeforeMapClass += (inspector, type, map) => map.Id(x => x.Generator(Generators.HighLow));
			mapper.BeforeMapClass += (inspector, type, map) => map.Cache(x => x.Usage(CacheUsage.ReadWrite));
			mapper.BeforeMapSet += (inspector, property, map) =>
			                       {
			                       	map.Cascade(Mapping.ByCode.Cascade.All);
			                       	map.Cache(x => x.Usage(CacheUsage.ReadWrite));
			                       };
			var mapping = mapper.CompileMappingFor(new[] { typeof(Blog), typeof(Post), typeof(Comment) });
			return mapping;
		}
开发者ID:prime,项目名称:nshibernate,代码行数:13,代码来源:CachingWithTrasformerTests.cs


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