Example #1
0
        public HttpResponseMessage Get()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["CraftingTable"].ConnectionString;
            IDbConnection sqlConnection = new SqlConnection(connectionString);

            //var appUsers1 = sqlConnection.Query<AppUser>("Select * from AppUsers").ToArray<AppUser>();
            var appUsers = sqlConnection.GetAll<AppUser>().ToArray<AppUser>();

            sqlConnection.Close();

            return Request.CreateResponse(
                HttpStatusCode.OK,
                new AppUsersModel {AppUsers = appUsers});
        }
Example #2
0
        private static void Dapper(int eachCount)
        {
            GC.Collect();//回收资源
            System.Threading.Thread.Sleep(2000);//休息2秒

            //正试比拼
            PerHelper.Execute(eachCount, "Dapper", () =>
            {
                using (SqlConnection conn = new SqlConnection(PubConst.connectionString))
                {
                    var list = conn.GetAll<Test>();
                }
            });
        }
Example #3
0
		public static void GetMethods()
		{
			using (var cn = new SqlConnection(CONNECTION_STRING))
			{
				var contact = cn.Get<Contact>(1);
				var contacts = cn.GetAll<Contact>();

				Console.WriteLine(
					"Found contact {0} {1} and {2} total contacts",
					contact.FirstName,
					contact.LastName,
					contacts.Count());
			}

			Console.ReadKey();
		}