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


C# ConventionModelMapper.Class方法代码示例

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


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

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

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

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

		protected override HbmMapping GetMappings()
		{
			var mapper = new ConventionModelMapper();
			System.Type baseEntityType = typeof (DomainObject);
			mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && !baseEntityType.Equals(t));
			mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));
			mapper.Class<DomainObject>(r =>
			                           {
			                           	r.Version(x => x.EntityVersion, map => { });
			                           	r.Id(x => x.ID, map => map.Generator(Generators.Native));
			                           });
			mapper.Class<Class1>(r => { r.IdBag(x => x.Class2List, map => map.Inverse(true), rel => rel.ManyToMany()); });
			mapper.Class<Class2>(r => { r.IdBag<Class1>("_class1List", map => { }, rel => rel.ManyToMany()); });
			HbmMapping mappings = mapper.CompileMappingFor(new[] {typeof (Class1), typeof (Class2)});
			return mappings;
		}
开发者ID:Ruhollah,项目名称:nhibernate-core,代码行数:16,代码来源:Fixture.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: 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

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

示例8: CustomizeMapping

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

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

示例10: CreateMappingConfiguration

        public static HbmMapping CreateMappingConfiguration()
        {
            var mapper = new ConventionModelMapper();

            var baseEntityType = typeof (Entity);
            mapper.IsEntity((t, declared) => baseEntityType.IsAssignableFrom(t) && baseEntityType != t && !t.IsInterface);
            mapper.IsRootEntity((t, declared) => baseEntityType.Equals(t.BaseType));

            mapper.BeforeMapManyToOne += (insp, prop, map) => map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");
            mapper.BeforeMapBag += (insp, prop, map) => map.Key(km => km.Column(prop.GetContainerEntity(insp).Name + "Id"));
            mapper.BeforeMapBag += (insp, prop, map) => map.Cascade(Cascade.All);

            mapper.Class<Album>(map => map.Id(x => x.AlbumId, m=> m.Generator(Generators.Identity)));
            mapper.Class<Artist>(map => map.Id(x => x.ArtistId, m => m.Generator(Generators.Identity)));

            var mapping = mapper.CompileMappingFor(baseEntityType.Assembly.GetExportedTypes());

            return mapping;
        }
开发者ID:mravinale,项目名称:simple-cqrs,代码行数:19,代码来源:EntitiesMapper.cs

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

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

示例13: 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;
			Assert.That(hbmId, Is.Not.Null);
			Assert.That(hbmId.generator, Is.Not.Null);
			Assert.That([email protected], Is.EqualTo("guid"));
			Assert.That(hbmId.type1, Is.EqualTo("Guid"));
		}
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:13,代码来源:SafePoidTests.cs

示例14: ConfigureMapping

        public override void ConfigureMapping(NHibernate.Cfg.Configuration configuration)
        {
            var mapper = new ConventionModelMapper();

            mapper.BeforeMapProperty += (inspector, member, customizer) =>
            {
                if (member.LocalMember.GetPropertyOrFieldType() == typeof(string))
                {
                    customizer.Length(50);
                }
            };
            mapper.BeforeMapClass += (inspector, type, customizer) => customizer.Id(im => im.Generator(Generators.GuidComb));
            // define the mapping shape

            mapper.Class<Hotel>(ca => ca.List(item => item.Reservations, cm => cm.Key(km => km.Column("HotelId"))));
            mapper.Class<Room>(ca => ca.List(item => item.Reservations, cm => cm.Key(km =>
                                                                                               	{
                                                                                               		km.Column("RoomId");
                                                                                               		km.OnDelete(OnDeleteAction.NoAction);
                                                                                               	})));
            mapper.Class<Reservation>(ca =>
                                          	{
                                                ca.ManyToOne(item => item.Hotel, m => { m.Column("HotelId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy);} );
                                                ca.ManyToOne(item => item.Room, m => { m.Column("RoomId"); m.Insert(false); m.Update(false); m.Lazy(LazyRelation.Proxy); });
                                          	});

            // list all the entities we want to map.
            IEnumerable<Type> baseEntities = GetMappingTypes();

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

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

            SessionFactory.SessionFactoryInstance = configuration.BuildSessionFactory();
        }
开发者ID:vlko,项目名称:vlko,代码行数:39,代码来源:IoCNRepositoryLinqTest.cs

示例15: GetMappingWithParentInCompo

		private HbmMapping GetMappingWithParentInCompo()
		{
			var mapper = new ConventionModelMapper();
			mapper.Class<MyClass>(x =>
			{
				x.Id(c => c.Id);
				x.Component(c => c.Compo);
			});
			mapper.Component<MyCompo>(x =>
			{
				x.Property(c => c.Something);
			});
			return mapper.CompileMappingForAllExplicitlyAddedEntities();
		}
开发者ID:owerkop,项目名称:nhibernate-core,代码行数:14,代码来源:ComponetsAccessorTests.cs


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