本文整理汇总了C#中Person.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Person.Delete方法的具体用法?C# Person.Delete怎么用?C# Person.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.Delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//TODO: Change querystring to posted value for security
Person person;
SqlConnection sqlConnection;
if (Request.QueryString["id"] != null)
{
//Create connection to database
sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["TutorialConnection"].ConnectionString);
person = new Person(sqlConnection);
int id = int.Parse(Request.QueryString["id"].ToString());
person.Delete(id);
Response.Redirect("Edit.aspx");
}
//if file is accessed directly redirect
Response.Redirect("Edit.aspx");
}
示例4: 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.
}