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


C# PhoneNumber.Save方法代码示例

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


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

示例1: OnInit

        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);

            ActiveRecordStarter.ResetInitializationFlag();
            ActiveRecordStarter.Initialize(typeof(Person).Assembly, ActiveRecordSectionHandler.Instance);
            NHibernate.Cfg.Environment.UseReflectionOptimizer = false;

            try
            {
                _log.Debug("Creating database...");
                RecreateDatabase();
                _log.Debug("...database created");
            }
            catch (ActiveRecordException exc)
            {
                _log.Fatal("Did you forget to modify 'connection.connection_string' in web.config to point to a valid database?", exc);
                return;
            }

            Person person;
            PhoneNumber homePhoneNumber;

            _log.Debug("Writing data to database...");
            using (TransactionScope trans = new TransactionScope())
            {
                person = new Person();
                person.Name = "Lazy";
                person.Save();

                homePhoneNumber = new PhoneNumber();
                homePhoneNumber.Number = "867-5309";
                homePhoneNumber.PhoneType = "Cell";
                homePhoneNumber.Person = person;
                homePhoneNumber.Save();

                trans.VoteCommit();
            }
            _log.Debug("...data written");

            int personId = person.Id;
            person = null;

            int homePhoneNumberId = homePhoneNumber.Id;
            homePhoneNumber = null;

            try
            {
                using (new SessionScope())
                {
                    Person lazyPerson = Person.TryFind(personId);

                    _log.Debug("Lazy loading an entity...");
                    string lazyName = lazyPerson.Name;
                    _log.Debug("...entity loaded");
                }

                using (new SessionScope())
                {
                    PhoneNumber home = PhoneNumber.Find(homePhoneNumberId);

                    _log.Debug("Lazy loading a related entity...");
                    Person lazyPerson = home.Person;
                    _log.Debug("...related entity loaded");
                }

                _log.Debug("Comment out 'proxyfactory.factory_class' in web.config and try again.");
            }
            catch (ActiveRecordException exc)
            {
                _log.Error("Cannot generate lazy loading proxies in a Medium Trust environment.  Try using NHibernate.ProxyGenerators :)", exc);
            }
        }
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:73,代码来源:Default.aspx.cs


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