zoukankan      html  css  js  c++  java
  • 开放源码的对象关系映射工具ORM.NET 删除数据 Deleting Records using ORM.NET

    删除一笔记录 Object].Delete()

    下面的代码,删除FirstName为Tim,LastName为Brown的学生

    DataManager dm = new DataManager(Config.Dsn);
    dm.QueryCriteria.Clear();
    dm.QueryCriteria.And(JoinPath.Student.Columns.FirstName,”Tim”)
                    .And(JoinPath.Student.Columns.LastName,”Brown”);
    Student s = dm.GetStudent(FetchPath.Student);
    s.Delete(); // marks the returned DataRow to be deleted
    dm.CommitAll();  // performs the necessary insert,update and delete operations

    删除多行记录

    DataManager dm = new DataManager(Config.Dsn);
    dm.QueryCriteria.And(JoinPath.Student.Columns.FirstName,"Tim")
                          .And(JoinPath.Student.Columns.LastName,"Brown");
    StudentCollection students = dm.GetStudentCollection();
    // check to ensure that there are record(s) to delete
    if (students != null) 
    {
             foreach (Student s in students)
                   s.Delete(); // loop through and mark for deletion 
            dm.CommitAll();  // Delete all datarows marked for deletion transitionally
    }
     

    先取出数据到Collection中,再用object.Delete标记为删除,在CommitAll方法中执行删除记录

     

    删除主从表记录 Delete Parent and Child record(s)

    请看代码,先读取Brown学生的数据和它联系方式,之后再删除联系方式和Brown学生记录。

    dm.QueryCriteria.Clear();
    dm.QueryCriteria.And(JoinPath.Student.Columns.LastName,"Brown");
    // Get[Object] will retrieve Student and related Contact records
    Student student = dm.GetStudent(FetchPath.Student.Contact);
    student.Contact.Delete();      // mark the Parent Contact record to be deleted
    student.Delete();              // mark Student record Root object to be deleted
    dm.CommitAll();
  • 相关阅读:
    linux引导系统
    Android开发面试经——2.常见Android基础笔试题
    Android开发面试经——1.常见人事面试问题
    Android面试题整理【转载】
    android设置软键盘搜索键以及监听搜索键点击时发生两次事件的问题解决
    Android软键盘弹出时把布局顶上去的解决方法
    Android入门:绑定本地服务
    Android aidl Binder框架浅析
    Android LayoutInflater深度解析 给你带来全新的认识
    Android RecyclerView 使用完全解析 体验艺术般的控件
  • 原文地址:https://www.cnblogs.com/JamesLi2015/p/2178782.html
Copyright © 2011-2022 走看看