当前位置: 首页 > 工具软件 > Lor > 使用案例 >

Lor进展——二

廉展鹏
2023-12-01

年末将至,由于各种原因Lor最近没有任何进展,实在可惜。不过为了给大家一个补偿,以下奉献出一段Lor的C#代码使用,看看Lor与其他O/R Mapping产品相比有什么与众不同之处。

BookList books = (BookList) DataCenter.Query("select {Book.Price} from {Book} where year({Book.PublishedDate})=1993 and {Book.Authors.LastName}='张'");
foreach (Book book in books) {
   book.Authors[0].LastName.Value = "袁";
   if (book.Price.IsValid(book.Price.Value * 0.80)) {
      book.Price.Value = book.Price.Value * 0.80;
   }
}
// 将整个List作为事务。
SaveResult result = books.Save();
if (result.Failed) {
   if (result.FailedReason == FailedReason.DataConflict) {
      result.CommitOverwrite();
//      result.Ignore();
   } else {
      result.Rollback();
   }
}

//
// 与用户控件的绑定。
//
books.DefaultView.Bind("C#", new string[] {"Name", "Price", "Authors Name = Authors[*].Name"}); books.DefaultView.Filter("C#", "Authors.Count > 1 && Authors[*].Address.City == /"长春/""); books.DefaultView.Sort("C#", new string[] {"Price, DES", "Name, ASC", "Authors[0].Name, ASC"}); this.dataGrid1.DataSource = books;

BookList books = (BookList) DataCenter.Query("select {Book.Price} from {Book} where year({Book.PublishedDate})=1993 and {Book.Authors.LastName}='张'");
foreach (Book book in books) {
   book.Authors[0].LastName.Value = "袁";
   if (book.Price.IsValid(book.Price.Value * 0.80)) {
      book.Price.Value = book.Price.Value * 0.80;
   }
}
// 将整个List作为事务。
SaveResult result = books.Save();
if (result.Failed) {
   if (result.FailedReason == FailedReason.DataConflict) {
      result.CommitOverwrite();
//      result.Ignore();
   } else {
      result.Rollback();
   }
}

//
// 与用户控件的绑定。
//
books.DefaultView.Bind("C#", new string[] {"Name", "Price", "Authors Name = Authors[*].Name"}); books.DefaultView.Filter("C#", "Authors.Count > 1 && Authors[*].Address.City == /"长春/""); books.DefaultView.Sort("C#", new string[] {"Price, DES", "Name, ASC", "Authors[0].Name, ASC"}); this.dataGrid1.DataSource = books;

BookList books = (BookList) DataCenter.Query("select {Book.Price} from {Book} where year({Book.PublishedDate})=1993 and {Book.Authors.LastName}='张'");
foreach (Book book in books) {
   book.Authors[0].LastName.Value = "袁";
   if (book.Price.IsValid(book.Price.Value * 0.80)) {
      book.Price.Value = book.Price.Value * 0.80;
   }
}
// 将整个List作为事务。
SaveResult result = books.Save();
if (result.Failed) {
   if (result.FailedReason == FailedReason.DataConflict) {
      result.CommitOverwrite();
//      result.Ignore();
   } else {
      result.Rollback();
   }
}

//
// 与用户控件的绑定。
//
books.DefaultView.Bind("C#", new string[] {"Name", "Price", "Authors Name = Authors[*].Name"}); books.DefaultView.Filter("C#", "Authors.Count > 1 && Authors[*].Address.City == /"长春/""); books.DefaultView.Sort("C#", new string[] {"Price, DES", "Name, ASC", "Authors[0].Name, ASC"}); this.dataGrid1.DataSource = books;

以上是一段用Lor得到的C#源代码写的示例,其中展示了一部分Lor在.NET平台下的独特之处。这里所展示的只是在目前设计阶段决定采用的调用方式,在后期很有可能还会变化,敬请期待!^_^

 类似资料: