/// <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.InsertQueue(new OrmOnly { Value = 1 }); foreach (OrmOnly value in sqlTable.SelectQueue().Value) { Console.WriteLine(value.toJson()); sqlTable.UpdateQueue(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.SelectQueue().Value) { Console.WriteLine(value.toJson()); Interlocked.Increment(ref deleteCount); sqlTable.DeleteQueue(value.Id, onDeleted); } onDeleted(); deleteWait.WaitOne(); } } }
/// <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); } } }