Example #1
0
 /// <summary>
 /// 简单 ORM 映射
 /// </summary>
 internal static void Test()
 {
     using (AutoCSer.Sql.ModelTable <OrmOnly> sqlTable = AutoCSer.Sql.ModelTable <OrmOnly> .Get())
     {
         AutoCSer.Metadata.MemberMap <OrmOnly> updateMemberMap = sqlTable.CreateMemberMap().Set(value => value.Value);
         sqlTable.Insert(new OrmOnly {
             Value = 1
         });
         foreach (OrmOnly value in sqlTable.Select())
         {
             Console.WriteLine(value.toJson());
             sqlTable.Update(new OrmOnly {
                 Id = value.Id, Value = value.Value + 1
             }, updateMemberMap);
         }
         //foreach (OrmOnly value in sqlTable.Select())
         //{
         //    Console.WriteLine(value.toJson());
         //    sqlTable.Delete(value.Id);
         //}
         using (deleteWait = new AutoResetEvent(false))
         {
             deleteCount = 1;
             foreach (OrmOnly value in sqlTable.Select())
             {
                 Console.WriteLine(value.toJson());
                 Interlocked.Increment(ref deleteCount);
                 sqlTable.Delete(value.Id, onDeleted);
             }
             onDeleted();
             deleteWait.WaitOne();
         }
     }
 }
Example #2
0
 /// <summary>
 /// 简单 ORM 映射
 /// </summary>
 internal static void Test()
 {
     using (AutoCSer.Sql.ModelTable <OrmOnly> sqlTable = AutoCSer.Sql.ModelTable <OrmOnly> .Get())
     {
         AutoCSer.Metadata.MemberMap <OrmOnly> updateMemberMap = sqlTable.CreateMemberMap().Set(value => value.Value);
         sqlTable.Insert(new OrmOnly {
             Value = 1
         });
         foreach (OrmOnly value in sqlTable.Select())
         {
             Console.WriteLine(value.toJson());
             sqlTable.Update(new OrmOnly {
                 Id = value.Id, Value = value.Value + 1
             }, updateMemberMap);
         }
         foreach (OrmOnly value in sqlTable.Select())
         {
             Console.WriteLine(value.toJson());
             sqlTable.Delete(value.Id);
         }
     }
 }