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


C# Configuration.AddDeserializedMapping方法代码示例

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


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

示例1: SaveExamUser

        /// <summary>
        /// 保存考试人信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int SaveExamUser(ExamUser model)
        {
            int id = -1;
            if (model != null)
            {
                var conf = new Configuration().Configure();
                ISession session = NHibernateHelper.GetSession();
                //配置NHibernate
                //在Configuration中添加HbmMapping
                conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<ExamUser>(), "ExamUserXML");
                //配置数据库架构元数据
                SchemaMetadataUpdater.QuoteTableAndColumns(conf);

                //建立SessionFactory
                var factory = conf.BuildSessionFactory();
                //打开Session做持久化数据
                using (session = factory.OpenSession())
                {
                    using (var tx = session.BeginTransaction())
                    {
                        id = (int)session.Save(model);
                        tx.Commit();
                    }
                }
            }
            return id;
        }
开发者ID:wgang10,项目名称:ZYWeb,代码行数:32,代码来源:ExamUserOP.cs

示例2: DeleteMember

        /// <summary>
        /// 删除会员
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool DeleteMember(Member model)
        {
            bool isSuccess = false;
            if (model != null)
            {
                var conf = new Configuration().Configure();
                ISession session = NHibernateHelper.GetSession();
                //配置NHibernate
                //在Configuration中添加HbmMapping
                conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<Member>(), "MemberXML");
                //配置数据库架构元数据
                SchemaMetadataUpdater.QuoteTableAndColumns(conf);

                //建立SessionFactory
                var factory = conf.BuildSessionFactory();
                //打开Session做持久化数据
                using (session = factory.OpenSession())
                {
                    using (var tx = session.BeginTransaction())
                    {
                        session.Delete(model);
                        tx.Commit();
                        isSuccess = true;
                    }
                }
            }
            return isSuccess;
        }
开发者ID:wgang10,项目名称:ZYWeb,代码行数:33,代码来源:MemberOP.cs

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

示例4: AddNHibernateSessionFactory

        public static void AddNHibernateSessionFactory(this IServiceCollection services)
        {
            // By default NHibernate looks for hibernate.cfg.xml
            // otherwise for Web it will fallback to web.config
            // we got one under wwwroot/web.config
            Configuration config = new Configuration();
            config.Configure();

            // Auto load entity mapping class
            ModelMapper mapper = new ModelMapper();
            mapper.AddMappings(Assembly.GetAssembly(typeof(Employee)).GetExportedTypes());

            HbmMapping mapping = mapper.CompileMappingForAllExplicitlyAddedEntities();
            config.AddDeserializedMapping(mapping, "NHibernate.Mapping");

            SchemaMetadataUpdater.QuoteTableAndColumns(config);

            // Drop & Recreate database schema
            new SchemaExport(config).Drop(false, true);
            new SchemaExport(config).Create(false, true);

            // Register services
            services.AddSingleton<ISessionFactory>(provider => config.BuildSessionFactory());
            services.AddTransient<ISession>(provider => services.BuildServiceProvider().GetService<ISessionFactory>().OpenSession());
        }
开发者ID:csokun,项目名称:WebApiNHibernate,代码行数:25,代码来源:NHibernateSessionFactory.cs

示例5: TestEvent

        public void TestEvent()
        {
            var config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.DataBaseIntegration(db =>
            {
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
            });

            config.EventListeners.SaveEventListeners = new ISaveOrUpdateEventListener[] 
            { 
                new TestSaveOrUpdateEventListener()
            };

            config.AddDeserializedMapping(InternalHelper.GetAllMapper(), "Models");

            var factory = config.BuildSessionFactory();

            using (var session = factory.OpenSession())
            {
                session.Save(new Message() { Content = "Message1" });
                session.Flush();
            }

            using (var session = factory.OpenSession())
            {
                var message = session.Get<Message>(1);
                Assert.IsNotNull(message.Creator);
                Assert.AreEqual(message.LastEditor, "Leoli_SaveOrUpdate_Event");
            }
        }
开发者ID:leejulee,项目名称:NhibernateTest,代码行数:31,代码来源:UnitTestEvent.cs

示例6: GetNewsList

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IList<Notic> GetNewsList(string SystemName, int Num)
        {
            ISession session = NHibernateHelper.GetSession();
            //配置NHibernate
            var conf = new Configuration().Configure();
            //在Configuration中添加HbmMapping
            conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<Notic>(), "NoticXML");
            //配置数据库架构元数据
            SchemaMetadataUpdater.QuoteTableAndColumns(conf);

            //建立SessionFactory
            var factory = conf.BuildSessionFactory();
            //打开Session做持久化数据
            using (session = factory.OpenSession())
            {
                IList<Notic> query;
                if (string.IsNullOrEmpty(SystemName))
                {
                    query = session.QueryOver<Notic>()
                    .OrderBy(p => p.CreateTime).Desc
                        .List();
                }
                else
                {
                    query = session.QueryOver<Notic>()
                    .Where(p => p.SystemName == SystemName)
                    .Where(p => p.Status != 2)
                    .OrderBy(p => p.CreateTime).Desc
                        .List();
                }

                return query;
            }
        }
开发者ID:wgang10,项目名称:XTHospatal,代码行数:38,代码来源:OptionNews.cs

示例7: TestEvent2

        public void TestEvent2()
        {
            var config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.DataBaseIntegration(db =>
            {
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
            });

            config.SetListener(ListenerType.PreUpdate, new TestUpdateEventListener());

            config.AddDeserializedMapping(InternalHelper.GetAllMapper(), "Models");

            var factory = config.BuildSessionFactory();

            using (var session = factory.OpenSession())
            {
                session.Save(new Message() { Content = "Message1", Creator = "Leoli_EventTest" });
                session.Flush();
            }

            using (var session = factory.OpenSession())
            {
                var message = session.Get<Message>(1);
                message.Content = "Message_Leoli2";
                session.Save(message);
                session.Flush();
                Assert.AreEqual(message.LastEditor, "Leoli_Update_Event");
            }
        }
开发者ID:leejulee,项目名称:NhibernateTest,代码行数:30,代码来源:UnitTestEvent.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: DeletePaperQuestions

        /// <summary>
        /// 根据试卷ID和试题ID删除试卷试题
        /// </summary>
        /// <param name="PaperId"></param>
        /// <param name="QuestionsId"></param>
        /// <returns></returns>
        public static int DeletePaperQuestions(int PaperId, int QuestionsId)
        {
            int number = -1;
            ISession session = NHibernateHelper.GetSession();
            //配置NHibernate
            var conf = new Configuration().Configure();
            //在Configuration中添加HbmMapping
            conf.AddDeserializedMapping(NHibernateHelper.GetEntityMapping<PaperQuestions>(), "PaperQuestionsXML");
            //配置数据库架构元数据
            SchemaMetadataUpdater.QuoteTableAndColumns(conf);

            //建立SessionFactory
            var factory = conf.BuildSessionFactory();
            //打开Session做持久化数据
            using (session = factory.OpenSession())
            {
                using (var tx = session.BeginTransaction())
                {
                    //var query = session.QueryOver<PaperQuestions>()
                    //.Where(p => p.PaperId == PaperId)
                    //.Where(p => p.QuestionsId == QuestionsId)
                    ////.Where("Name like '%我的测试'")
                    ////.OrderBy(p => p.TypeID).Asc
                    //.List();
                    number = session.Delete ("from PaperQuestions p Where p.PaperId=" + PaperId.ToString() + " and p.QuestionsId = " + QuestionsId.ToString());
                    //number = session.CreateQuery("delete from PaperQuestions Where PaperId=" + PaperId.ToString() + " and QuestionsId = " + QuestionsId.ToString()).ExecuteUpdate();
                    //var domain = new Domain { Id = 1, Name = "我的测试" + DateTime.Now.ToString() };
                    //s.Delete(domain);
                    tx.Commit();
                    return number;
                }
            }
        }
开发者ID:wgang10,项目名称:ZYWeb,代码行数:39,代码来源:ExamPaperOP.cs

示例10: WithConventions

        public static void WithConventions(this ConventionModelMapper mapper, Configuration configuration) {
            Type baseEntityType = typeof(Entity);

            mapper.IsEntity((type, declared) => IsEntity(type));
            mapper.IsRootEntity((type, declared) => baseEntityType.Equals(type.BaseType));

            mapper.BeforeMapClass += (modelInspector, type, classCustomizer) => {
                classCustomizer.Id(c => c.Column("Id"));
                classCustomizer.Id(c => c.Generator(Generators.Identity));
                classCustomizer.Table(Inflector.Net.Inflector.Pluralize(type.Name.ToString()));
            };

            mapper.BeforeMapManyToOne += (modelInspector, propertyPath, map) => {
                map.Column(propertyPath.LocalMember.GetPropertyOrFieldType().Name + "Fk");
                map.Cascade(Cascade.Persist);
            };

            mapper.BeforeMapBag += (modelInspector, propertyPath, map) => {
                map.Key(keyMapper => keyMapper.Column(propertyPath.GetContainerEntity(modelInspector).Name + "Fk"));
                map.Cascade(Cascade.All);
            };

            AddConventionOverrides(mapper);

            HbmMapping mapping = mapper.CompileMappingFor(typeof(ActionConfirmation<>).Assembly.GetExportedTypes().Where(t => IsEntity(t)));
            configuration.AddDeserializedMapping(mapping, "TemplateSrcMappings");
        }
开发者ID:transformersprimeabcxyz,项目名称:Sharp-Lite,代码行数:27,代码来源:Conventions.cs

示例11: ConfigureNHibernate

		/// <summary>
		/// Configure NHibernate
		/// </summary>
		private static Configuration ConfigureNHibernate()
		{
			Configuration configure = new Configuration();
			configure.SessionFactoryName("SessionFactory");

			configure.DataBaseIntegration(db =>
				{
					db.Dialect<MsSql2008Dialect>();
					db.Driver<SqlClientDriver>();
					db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
					db.IsolationLevel = IsolationLevel.ReadCommitted;

					db.ConnectionStringName = RegtestingServerConfiguration.DefaultConnectionString;
					//db.Timeout = 10;

					//For testing
					//db.LogFormattedSql = true;
					//db.LogSqlInConsole = true;
					//db.AutoCommentSql = true;
				});

			HbmMapping hbmMapping = GetMappings();
			configure.AddDeserializedMapping(hbmMapping,"NHMapping");
			SchemaMetadataUpdater.QuoteTableAndColumns(configure);

			return configure;
		}
开发者ID:florianwittmann,项目名称:regtesting,代码行数:30,代码来源:ApplicationContext.cs

示例12: ConfigureNHibernate

        static Configuration ConfigureNHibernate()
        {
            var configure = new Configuration();
            configure.SessionFactoryName("HemArkivAccess");

            configure.DataBaseIntegration(db =>
            {
                db.Dialect<NHibernate.JetDriver.JetDialect>();
                db.Driver<NHibernate.JetDriver.JetDriver>();
                db.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;

                db.ConnectionStringName = "HemArkivAccess";
                db.Timeout = 10;

                // enabled for testing
                db.LogFormattedSql = true;
                db.LogSqlInConsole = false;
                db.AutoCommentSql = false;
                db.Timeout = 10;
                //db.ConnectionProvider<NHibernate.Connection.DriverConnectionProvider>();
            });

            var mapping = GetMappings();
            configure.AddDeserializedMapping(mapping, "HemArkivAccess");

            return configure;
        }
开发者ID:marcusholmgren,项目名称:NHemarkiv,代码行数:27,代码来源:ConfigurationBuilder.cs

示例13: SetUp

		public void SetUp()
		{
			var configuration = new Configuration();
			configuration
				.SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, "true")
				.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, "create-drop")
				.SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true")
				.SetProperty(NHibernate.Cfg.Environment.CacheProvider, typeof (HashtableCacheProvider).AssemblyQualifiedName)
				.SetProperty(NHibernate.Cfg.Environment.ReleaseConnections, "on_close")
				.SetProperty(NHibernate.Cfg.Environment.Dialect, typeof (SQLiteDialect).AssemblyQualifiedName)
				.SetProperty(NHibernate.Cfg.Environment.ConnectionDriver, typeof (SQLite20Driver).AssemblyQualifiedName)
				.SetProperty(NHibernate.Cfg.Environment.ConnectionString, "Data Source=:memory:;Version=3;New=True;");

			var assembly = Assembly.GetExecutingAssembly();

			var modelMapper = new ModelMapper();
			modelMapper.AddMappings(assembly.GetTypes());
			var hbms = modelMapper.CompileMappingForAllExplicitlyAddedEntities();
			configuration.AddDeserializedMapping(hbms, assembly.GetName().Name);

			ConfigureSearch(configuration);

			sessionFactory = configuration.BuildSessionFactory();

			Session = sessionFactory.OpenSession();
			SearchSession = Search.CreateFullTextSession(Session);

			new SchemaExport(configuration)
				.Execute(false, true, false, Session.Connection, null);

			AfterSetup();
		}
开发者ID:vcaraulean,项目名称:NHibernate.Search,代码行数:32,代码来源:FluentSearchTestBase.cs

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

示例15: CriarSchema

        public void CriarSchema()
        {
            // Apenas no Init da Aplicação

            var config = new Configuration();

            config.DataBaseIntegration(c =>
            {
                c.Dialect<MsSql2012Dialect>();
                c.ConnectionStringName = "ExemploNH";
                c.LogFormattedSql = true;
                c.LogSqlInConsole = true;
                c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
            });

            var modelMapper = new ModelMapper();

            modelMapper.AddMappings(typeof (ProdutoMap).Assembly.GetExportedTypes());

            config.AddDeserializedMapping(modelMapper.CompileMappingForAllExplicitlyAddedEntities(), "Domain");

            ISessionFactory sessionFactory = config.BuildSessionFactory();

            // NOTE: Estudar framework FluentMigration
            var schemaExport = new SchemaExport(config);

            schemaExport.Create(true, true);
        }
开发者ID:TiagoSoczek,项目名称:MOC,代码行数:28,代码来源:SchemaTestCase.cs


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