소스 객체 관계 매핑 도구 ORM을 엽니다.NET 데이터 삭제 Deleting Records using ORM.NET

4851 단어 .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


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
여러 줄 레코드 삭제
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)
코드를 보십시오. 먼저 브라운 학생의 데이터와 연락처를 읽은 다음 연락처와 브라운 학생 기록을 삭제하십시오.
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();


.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

좋은 웹페이지 즐겨찾기