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


C# Person.Delete方法代码示例

本文整理汇总了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();
        }
开发者ID:brendankowitz,项目名称:systembusinessobjects,代码行数:9,代码来源:ContactContext.cs

示例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();
        }
开发者ID:ajvorobiev,项目名称:DotNORM,代码行数:25,代码来源:Model.cs

示例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");
    }
开发者ID:jhawkheadnz,项目名称:Web3Tutorial2012,代码行数:23,代码来源:Delete.aspx.cs

示例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.
        }
开发者ID:ajvorobiev,项目名称:DotNORM,代码行数:47,代码来源:Model.cs


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