本文整理汇总了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);
}
}