本文整理汇总了C#中Person.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Person.Save方法的具体用法?C# Person.Save怎么用?C# Person.Save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRemoveStandartStringAttributes
public void AddRemoveStandartStringAttributes()
{
m_Person = new Person();
m_Person.LastName = new MLText("en", "Yakimov");
m_Person.PersonGender = Person.Gender.Male;
Assert.IsFalse(m_Person.ID.HasValue);
m_Person.Save();
Assert.IsTrue(m_Person.ID.HasValue);
try
{
PersonAttribute[] coll;
m_Person.AddStandardStringAttribute(PersonAttributeTypes.EMail, "[email protected]");
coll = PersonAttributes.GetPersonAttributesByKeyword(m_Person.ID.Value, PersonAttributeTypes.EMail.ToString());
Assert.AreEqual(1, coll.Length);
m_Person.AddStandardStringAttribute(PersonAttributeTypes.EMail, "[email protected]");
coll = PersonAttributes.GetPersonAttributesByKeyword(m_Person.ID.Value, PersonAttributeTypes.EMail.ToString());
Assert.AreEqual(2, coll.Length);
m_Person.RemoveStandardAttributes(PersonAttributeTypes.EMail);
coll = PersonAttributes.GetPersonAttributesByKeyword(m_Person.ID.Value, PersonAttributeTypes.EMail.ToString());
Assert.AreEqual(0, coll.Length);
}
finally
{ m_Person.Delete(); }
}
示例2: SaveUserChanges
/// <summary>
/// Saves information about user and returns modified user.
/// </summary>
/// <returns>Object of modified user.</returns>
public virtual Person SaveUserChanges()
{
Person user = new Person();
if (UserID != null)
user.Load(UserID.Value);
user.FirstName = tbFirstName.MultilingualText;
user.MiddleName = tbMiddleName.MultilingualText;
user.LastName = tbLastName.MultilingualText;
user.Sex = (Person.UserSex) ddlSex.SelectedIndex;
user.Birthday = string.IsNullOrEmpty(tbBirthday.Text)
? (DateTime?) null
: DateTime.Parse(tbBirthday.Text);
user.PrimaryEMail = tbPrimaryEMail.Text;
user.Project = tbProject.Text;
user.Room = tbRoom.Text;
user.PrimaryIP = tbPrimaryIP.Text;
user.Save();
dnEditor.GenerateDomainNames(user.ID.Value);
gmEditor.GenerateMembership(user.ID.Value);
return user;
}
示例3: LetsGetPersons
/// <summary>
/// Reads all persons and a single person, updates and deletes them.
/// </summary>
public static void LetsGetPersons()
{
// Query all objects of type <see
var people = Person.All();
// Get the number of people or any other type of manipulation using standard LINQ and C# methods
var numberOfPeople = people.Count;
var daves = people.Where(p => p.FirstName == "Dave");
var firstAlex = people.FirstOrDefault(p => p.FirstName == "Alex");
// Lets create an save a person.
var johndoe = new Person
{
Id = Guid.Parse("337DFD9D-7D46-40FF-8008-95A2FC781118"),
FirstName = "John",
LastName = "Doe",
Age = 24
};
johndoe.Save();
// Find a person by their primary key. This should return John Doe object.
var person = Person.Find(Guid.Parse("337DFD9D-7D46-40FF-8008-95A2FC781118"));
// Lets update and save his record
person.LastName = "Doe2";
person.Save();
// Let clean up
person.Delete();
}
示例4: CanSaveEmbeddedDocument
public void CanSaveEmbeddedDocument()
{
// Arrange.
var person = new Person
{
FirstName = "Tim",
LastName = "Jones"
};
var address = new Address
{
Street = "1 Recursive Loop",
City = "San Francisco",
State = "California",
Postcode = "1(1(1))"
};
// Act.
person.Address = address;
person.Save();
// Assert.
Assert.That(address.Parent, Is.EqualTo(person));
Assert.That(Person.GetCollection().Count(), Is.EqualTo(1));
Assert.That(Person.GetCollection().FindOne().ID, Is.EqualTo(person.ID));
Assert.That(Person.GetCollection().FindOne().Address.ID, Is.EqualTo(person.Address.ID));
}
示例5: LoadByDomainName_False
public void LoadByDomainName_False()
{
Person p = new Person();
Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));
m_Person = new Person();
m_Person.LastName = new MLText("en", "Yakimov");
m_Person.PersonGender = Person.Gender.Male;
Assert.IsFalse(m_Person.ID.HasValue);
m_Person.Save();
Assert.IsTrue(m_Person.ID.HasValue);
try
{
Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));
PersonAttribute pa = new PersonAttribute();
pa.PersonID = m_Person.ID.Value;
pa.InsertionDate = DateTime.Now;
pa.KeyWord = PersonAttributeTypes.DomainName.ToString();
pa.ValueType = typeof(string).AssemblyQualifiedName;
pa.StringField = @"ultersysyar\yim1";
pa.Save();
Assert.IsNotNull(pa.ID);
try
{
Assert.IsFalse(p.LoadByDomainName(@"ultersysyar\yim"));
}
finally
{ pa.Delete(); }
}
finally
{ m_Person.Delete(); }
}
示例6: DeletePerson
public void DeletePerson(Person obj)
{
if (SearchAddresses(obj.ID).Count > 0)
throw new DataException("Remove the child addresses before deleting the person");
Person.Evict(obj.ID);
obj.Delete();
obj.Save();
}
示例7: LetsCreateAPerson
/// <summary>
/// Creates, updates and deletes a person
/// </summary>
public static void LetsCreateAPerson()
{
// Create a new person object and set its properties
var person = new Person
{
Id = Guid.NewGuid(),
FirstName = "Alex",
LastName = "Vorobiev",
Age = 28
};
// Save that person to the database
person.Save();
// Want to update a person? Easy. Just save them again. If the person with the same id exists in the database
// they will be updated
person.LastName = "Papov";
person.Save();
// Remove the person from the database
person.Delete();
}
示例8: CanSaveAndLoadNullEmbeddedDocument
public void CanSaveAndLoadNullEmbeddedDocument()
{
// Arrange.
var person = new Person
{
FirstName = "Tim",
LastName = "Jones",
Address = null
};
// Act.
person.Save();
// Assert.
Assert.That(Person.GetCollection().Count(), Is.EqualTo(1));
Assert.That(Person.GetCollection().FindOne().ID, Is.EqualTo(person.ID));
Assert.That(Person.GetCollection().FindOne().Address, Is.Null);
}
示例9: HasManyAndBelongsToMany
public void HasManyAndBelongsToMany()
{
Company company = new Company("Castle Corp.");
company.Address = new PostalAddress(
"Embau St., 102", "Sao Paulo", "SP", "040390-060");
company.Save();
Person person = new Person();
person.Name = "ayende";
person.Companies.Add(company);
company.People.Add(person);
person.Save();
Company fromDB = Company.FindFirst();
Assert.AreEqual(1, fromDB.People.Count);
Assert.AreEqual("ayende", new List<Person>(fromDB.People)[0].Name);
}
示例10: UpdatePerson
public void UpdatePerson(Person obj)
{
Person.Evict(obj.ID);
obj.Save();
}
示例11: CreatePerson
public Person CreatePerson(Person obj)
{
obj.Save();
return obj;
}
示例12: LetsTryTransactions
/// <summary>
/// Creates a transaction object and uses it to perform some operations.
/// </summary>
public static void LetsTryTransactions()
{
// lets create some people to play with
var johndoe1 = new Person
{
Id = Guid.NewGuid(),
FirstName = "John1",
LastName = "Doe",
Age = 24
};
var johndoe2 = new Person
{
Id = Guid.NewGuid(),
FirstName = "John2",
LastName = "Doe",
Age = 24
};
var johndoe3 = new Person
{
Id = Guid.NewGuid(),
FirstName = "John3",
LastName = "Doe",
Age = 24
};
// Transactions allow you to group operations into one execution, meaning that if one operations fails, all
// are not performed on the database.
var transaction = DatabaseSession.Instance.CreateTransaction();
// once we have a transaction object we can pass it into any method for that method to use
johndoe1.Save(transaction: transaction);
johndoe2.Save(transaction: transaction);
johndoe3.Delete(transaction: transaction);
// now the 3 operations are stored on the transaction and have not been executed on the database yet.
// To execute them we need to commit them.
DatabaseSession.Instance.CommitTransaction(transaction);
// This will execute all 3 operations but because the last one is trying to delete a record on the database that
// does not exist yet all 3 will fail. This is in stark contrast to the case where no transaction is used
// and the first 2 operations would run fine.
}
示例13: SetUp
public void SetUp()
{
person = new Person();
person.Birthday = DateTime.Now;
person.EmployeesUlterSYSMoscow = true;
person.FirstName = new MLText( "en", "Tester", "ru", "Тест" );
person.LastName = new MLText( "en", "Tester", "ru", "Тестов" );
person.LongServiceEmployees = true;
person.MiddleName = new MLText( "en", "T.", "ru", "Тестович" );
person.PersonnelReserve = true;
person.PrimaryEMail = "[email protected]";
person.PrimaryIP = "127.0.0.1";
person.Project = "Project";
person.Room = "Room";
person.Sex = Person.UserSex.Female;
person.Save();
domainNameAttr = new PersonAttribute();
domainNameAttr.StringField = domainName;
domainNameAttr.ValueType = typeof( string ).AssemblyQualifiedName;
domainNameAttr.PersonID = person.ID.Value;
domainNameAttr.Save();
loaded = new Person();
loaded.Load( person.ID.Value );
/*group = new Group();
group.GroupType = Group.GroupsEnum.Employee;
group.Name = new MLText( "en", "Employees" );
group.Description = new MLText( "en", "Employees" );
group.Save();*/
}
示例14: 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);
}
}
示例15: CanLoadEmbeddedDocument
public void CanLoadEmbeddedDocument()
{
// Arrange.
var person = new Person
{
FirstName = "Tim",
LastName = "Jones"
};
var address = new Address
{
Street = "1 Recursive Loop",
City = "San Francisco",
State = "California",
Postcode = "1(1(1))"
};
person.Address = address;
person.Save();
// Act.
Person myPerson = Person.Find(person.ID);
// Assert.
Assert.That(myPerson.Address.Parent, Is.EqualTo(myPerson));
}