国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

dapper.rainbow

2019-11-17 02:50:55
字體:
來源:轉載
供稿:網友

dapper.rainbow

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Data.SqlClient; using Dapper; // to have a play, install Dapper.Rainbow from nuget namespace TestDapper{    class PRogram    {        // no decorations, base class, attributes, etc         class Product         {            public int Id { get; set; }            public string Name { get; set; }            public string Description { get; set; }            public DateTime? LastPurchase { get; set; }        }         // container with all the tables         class MyDatabase : Database<MyDatabase>        {            public Table<Product> Products { get; set; }        }         static void Main(string[] args)        {            var cnn = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Integrated Security=True");            cnn.Open();             var db = MyDatabase.Init(cnn, commandTimeout: 2);             try            {                db.Execute("waitfor delay '00:00:03'");            }            catch (Exception)            {                Console.WriteLine("yeah ... it timed out");            }              db.Execute("if object_id('Products') is not null drop table Products");            db.Execute(@"create table Products (                    Id int identity(1,1) primary key,                     Name varchar(20),                     Description varchar(max),                     LastPurchase datetime)");             int? productId = db.Products.Insert(new {Name="Hello", Description="Nothing" });            var product = db.Products.Get((int)productId);             product.Description = "untracked change";             // snapshotter tracks which fields change on the object             var s = Snapshotter.Start(product);            product.LastPurchase = DateTime.UtcNow;            product.Name += " World";                        // run: update Products set LastPurchase = @utcNow, Name = @name where Id = @id            // note, this does not touch untracked columns             db.Products.Update(product.Id, s.Diff());             // reload            product = db.Products.Get(product.Id);                         Console.WriteLine("id: {0} name: {1} desc: {2} last {3}", product.Id, product.Name, product.Description, product.LastPurchase);            // id: 1 name: Hello World desc: Nothing last 12/01/2012 5:49:34 AM             Console.WriteLine("deleted: {0}", db.Products.Delete(product.Id));            // deleted: True               Console.ReadKey();        }    }}

先mark下,有空測試下性能。 感覺很方便


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 略阳县| 永和县| 漯河市| 汝城县| 会东县| 从江县| 定兴县| 龙南县| 芒康县| 叶城县| 乌兰浩特市| 东方市| 鄂温| 同仁县| 壤塘县| 灵山县| 贵港市| 绥化市| 汾西县| 富宁县| 武冈市| 大兴区| 濮阳市| 太白县| 大宁县| 讷河市| 兴国县| 抚顺市| 大安市| 潜山县| 永春县| 连云港市| 宜都市| 英山县| 称多县| 吉安市| 高青县| 陇西县| 都安| 石狮市| 庆安县|