• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# PetaPoco.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中PetaPoco.Database的典型用法代码示例。如果您正苦于以下问题:C# PetaPoco.Database类的具体用法?C# PetaPoco.Database怎么用?C# PetaPoco.Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PetaPoco.Database类属于命名空间,在下文中一共展示了PetaPoco.Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Form1_Load

        private void Form1_Load(object sender, EventArgs e)
        {
            var db = new PetaPoco.Database("tencentcloud");

            //To query a scalar
            foreach(var a in db.Query<article>("select * from articles"))
            {
                listBox1.Items.Add(string.Format("{0}-{1}", a.article_id, a.title));
            }

            listBox1.Items.Add("\r\n");
            long count = db.ExecuteScalar<long>("select Count(*) from articles");
            listBox1.Items.Add(string.Format("count: {0}",count ));
            listBox1.Items.Add("\r\n");
            //@0  代表占位符  SingleOrDefault
            var abc = db.SingleOrDefault<article>("select * from articles where [email protected]",1);
            listBox1.Items.Add(abc);
            listBox1.Items.Add("\r\n");

            //Paged Fetches 分页
            var result = db.Page<article>(1, 3, "select * from articles where draft=1 order by date_created ");

            foreach (var temp in result.Items)
            {
                listBox1.Items.Add(string.Format("title: {0}", temp.title));
            }

            listBox1.Items.Add("\r\n");
            listBox1.Items.Add("结束");
        }
开发者ID:xinzhuxiansheng,项目名称:blog,代码行数:30,代码来源:Form1.cs


示例2: GetAllTag

 public static List<string> GetAllTag()
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.Query<string>("SELECT tag_title  FROM  jexus_tags  ORDER BY tag_title DESC").ToList();
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:7,代码来源:CommonDataProvider.cs


示例3: GetAllSetting

 /// <summary>
 /// 获取所有的
 /// </summary>
 /// <returns></returns>
 public static List<Settings> GetAllSetting()
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.Query<Models.Settings>("").ToList();
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:11,代码来源:CommonDataProvider.cs


示例4: GetAllPages

 public static List<Models.Page> GetAllPages()
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.Query<Models.Page>("").ToList();
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:7,代码来源:CommonDataProvider.cs


示例5: UpdateUser

 public static void UpdateUser(Models.User u)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         db.Save(u);
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:7,代码来源:AccountDataProvider.cs


示例6: GetUserGroup

 public static Models.UserGroup GetUserGroup(int id)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.SingleOrDefault<Models.UserGroup>("WHERE [email protected] ", id);
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:7,代码来源:AccountDataProvider.cs


示例7: GetUserByOpenID

 public static User GetUserByOpenID(string openid)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.SingleOrDefault<Models.User>("WHERE [email protected] ", openid);
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:7,代码来源:AccountDataProvider.cs


示例8: GetUser

 /// <summary>
 /// 根据登录名
 /// </summary>
 /// <param name="userName"></param>
 /// <returns></returns>
 public static User GetUser(string userName)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.SingleOrDefault<Models.User>("WHERE [email protected] ", userName);
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:12,代码来源:AccountDataProvider.cs


示例9: SelectAll

        private void SelectAll()
        {
            // Create a PetaPoco database object
            var db = new PetaPoco.Database("sqlite");

            string query = "SELECT * FROM foo";

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(query);
            sb.AppendLine("--------------");

            try
            {
                // Show all foo
                foreach (var a in db.Query<foo>(query))
                {
                    sb.AppendLine(string.Format("{0} - {1}", a.Id, a.name));
                }
            }
            catch (Exception ex)
            {
                sb.AppendLine(ex.Message);
                sb.Append(ex.StackTrace);
            }

            this.richTextBox1.Text = sb.ToString();
        }
开发者ID:jasonbrice,项目名称:MicroORMExample,代码行数:27,代码来源:FooQuery.cs


示例10: Delete

        public JsonResult Delete(IList<Route> data)
        {
            bool success = false;
            string message = "Delete method failed";

            if (data != null)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    foreach (var item in data)
                    {
                        item.EditDate = DateTime.Now;
                        item.Active = false;
                        db.Save("tblRoutes", "RouteKey", item);
                    }

                    success = true;
                    message = "Route(s) deleted successfully";
                }
            }

            return Json(new
            {
                success,
                message
            });
        }
开发者ID:fdlane,项目名称:MissNancy,代码行数:27,代码来源:RouteController.cs


示例11: Crud

        private static void Crud()
        {
            var petaPoco = new PetaPoco.Database("Chinook");

            var customer = new Customer { FirstName = "Ian", LastName = "Russell", Email = "[email protected]" };

            petaPoco.Insert(customer);

            var id = customer.CustomerId;

            customer = petaPoco.Single<Customer>(id);

            ObjectDumper.Write(customer);

            customer.Country = "United Kingdom";

            petaPoco.Update(customer);

            customer = petaPoco.Single<Customer>(id);

            ObjectDumper.Write(customer);

            petaPoco.Delete<Customer>(id);

            customer = petaPoco.SingleOrDefault<Customer>(id);

            ObjectDumper.Write(customer);
        }
开发者ID:ciker,项目名称:MicroORM,代码行数:28,代码来源:Program.cs


示例12: Post

        public IHttpActionResult Post([FromUri] string id, [FromBody]System.Collections.Generic.List<Entities.Contact> contactlist)
        {
            if (contactlist != null)
            {
                var db = new PetaPoco.Database("AGSoftware");

                List<Entities.Contact> newcontactlist = new List<Entities.Contact>();

                foreach (Entities.Contact contact in contactlist)
                {
                    var iscontact = db.SingleOrDefault<Entities.AspNetUsers>("Select * From ASPNetUsers Where PhoneNumber = @0", contact.PhoneNumber);

                    if (iscontact != null)
                    {
                        newcontactlist.Add(new Entities.Contact(iscontact.Id, iscontact.PhoneNumber, contact.FirstName, contact.LastName));
                    }
                }

                if (newcontactlist.Count > 0)
                    return Ok(newcontactlist);
                else
                    return NotFound();
            }
            else
            {
                return BadRequest("Contact List was empty");
            }
        }
开发者ID:AGSoftwareInc,项目名称:Storytime,代码行数:28,代码来源:ContactController.cs


示例13: Get

        public IHttpActionResult Get(string id)
        {
            var db = new PetaPoco.Database("AGSoftware");
            var db2 = new PetaPoco.Database("AGSoftware");
            System.Collections.Generic.List<Entities.StorytimePost> storytimepostlist = new List<Entities.StorytimePost>();

            string UserId = "";

            foreach (Entities.StorytimePost c in db.Query<Entities.StorytimePost>("Select * From StorytimePost Where SeriesId = @0 Order By DateCreated Desc", id))
            {
                c.ImagePath = Providers.ImageHelper.GetImagePath(c.ImagePath);
                c.ImagePath = c.ImagePath.Replace(@"\", @"/");
                UserId = Providers.UserHelper.GetUserId(this.User.Identity.Name);
                var voted  = db2.SingleOrDefault<Entities.Vote>("Select * From Vote Where StorytimePostId = @0 And UserId = @1", new object []{c.StorytimePostId, UserId});

                if (voted != null)
                    c.Voted = true;
                else
                    c.Voted = false;

                if (c.UserId == UserId)
                    c.UserPostedImage = true;

                c.PhoneNumber = Providers.UserHelper.GetPhoneNumberById(c.UserId);

                storytimepostlist.Add(c);
            }

            if (storytimepostlist.Count > 0)
                return Ok(storytimepostlist);
            else
                return NotFound();
        }
开发者ID:AGSoftwareInc,项目名称:Storytime,代码行数:33,代码来源:StorytimeSeriesController.cs


示例14: button3_Click

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                // Create a PetaPoco database object
                var db = new PetaPoco.Database("sqlite");

                // find the (presumably) most recently created foo
                int id = db.ExecuteScalar<int>("SELECT max(id) from foo");

                // Get a record
                var foo = db.SingleOrDefault<foo>("SELECT * FROM foo WHERE [email protected]", id);

                // Change it
                foo.name = "PetaPoco changed your name!";

                // Save it
                db.Update("foo", "Id", foo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
            }

            this.fooQuery1.Refresh();
        }
开发者ID:jasonbrice,项目名称:MicroORMExample,代码行数:26,代码来源:PetaPocoForm.cs


示例15: GetSetting

 /// <summary>
 /// 获取配置
 /// </summary>
 /// <param name="title"></param>
 /// <returns></returns>
 public static Settings GetSetting(string title)
 {
     using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
     {
         return db.SingleOrDefault<Models.Settings>("WHERE [email protected]", title);
     }
 }
开发者ID:ouyang90,项目名称:XBBS,代码行数:12,代码来源:CommonDataProvider.cs


示例16: dataBind

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        public void dataBind(int pageIndex = 1, int pageSize = 10, string startTime = null, string endTime = null)
        {
            PetaPoco.Sql sql = new PetaPoco.Sql();
            sql.Select("m.[description] as name,a.*").From("t_MachineStop_rd a");
            sql.LeftJoin("Point_Machine_Map m").On("m.pointname=a.pointname");
            if (!String.IsNullOrEmpty(startTime))
            {
                sql.Where("a.starttime>@0", startTime);
            }
            if (!String.IsNullOrEmpty(endTime))
            {
                sql.Where("a.starttime<@0", endTime);
            }
            List<int> machineids = new List<int>();
            for (int i = 0; i < chkboxlist.Items.Count; i++)
            {
                if (chkboxlist.Items[i].Selected)
                {
                    machineids.Add(int.Parse(chkboxlist.Items[i].Value));
                }
            }
            if (machineids.Count > 1)
                sql.Where("m.machineid in (@0)", machineids);
            else if (machineids.Count == 1)
                sql.Where("[email protected]", machineids[0]);

            sql.OrderBy("a.starttime desc");

            var db = new PetaPoco.Database("dbconn");
            PetaPoco.Page<BootRecordSelect> pageitems = db.Page<BootRecordSelect>(pageIndex, pageSize, sql);
            rpt_RulelogS_Des.DataSource = pageitems.Items;
            rpt_RulelogS_Des.DataBind();
            AspNetPager1.RecordCount = (int)pageitems.TotalItems;
        }
开发者ID:zhiqi1001,项目名称:ReportingServices-Reportservices_wenzhou,代码行数:39,代码来源:machine_startstop_ab_description.aspx.cs


示例17: Details

        //
        // GET: /Classes/Details/5
        public ActionResult Details(int id)
        {
            var db = new PetaPoco.Database("MissNancy");
            var myClass = db.SingleOrDefault<Classes>("SELECT * FROM tblClasses WHERE ClassKey = @0", id);

            return View(myClass);
        }
开发者ID:fdlane,项目名称:MissNancy,代码行数:9,代码来源:AgesController.cs


示例18: Post

        public IHttpActionResult Post()
        {
            var file = HttpContext.Current.Request.Files[0];

            if (file != null)
            {
                string filename = Guid.NewGuid().ToString() + file.FileName;
                string pic = System.IO.Path.GetFileName(filename);
                string path = System.IO.Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), pic);
                // file is uploaded
                file.SaveAs(path);

                var db = new PetaPoco.Database("AGSoftware");

                Entities.StorytimePost storytimepost = new Entities.StorytimePost();
                storytimepost.DateCreated = System.DateTime.Now;
                storytimepost.ImagePath = filename;
                storytimepost.PostText = HttpContext.Current.Request.Form["posttext"];
                storytimepost.UserId = Storytime.Providers.UserHelper.GetUserId(HttpContext.Current.User.Identity.Name);
                storytimepost.StorytimeId = int.Parse(HttpContext.Current.Request.Form["storytimeid"]);
                storytimepost.SeriesId = int.Parse(HttpContext.Current.Request.Form["SeriesId"]);

                db.Insert(storytimepost);

                return Ok(storytimepost.StorytimePostId);
            }
            else
            {
                return BadRequest("File upload missing.");
            }
        }
开发者ID:AGSoftwareInc,项目名称:Storytime,代码行数:31,代码来源:StorytimePostController.cs


示例19: Create

        public JsonResult Create(List<Bus> data)
        {
            bool success = false;
            string message = "Create method failed";

            if (data != null)
            {
                using (var db = new PetaPoco.Database("MissNancy"))
                {
                    foreach (var item in data)
                    {
                        item.CreateDate = DateTime.Now;
                        item.EditDate = DateTime.Now;
                        db.Save("tblBuses", "BusKey", item);
                    }

                    success = true;
                    message = "Jesus Saves and so did this method";
                }
            }

            return Json(new
            {
                data,
                success,
                message
            });
        }
开发者ID:fdlane,项目名称:MissNancy,代码行数:28,代码来源:BusesController.cs


示例20: TestMethodTable

        public void TestMethodTable()
        {
            var db = new PetaPoco.Database(connectionString, providerName);
            var keyObjectStore = new SqlKeyObjectStore(db);

            using (var myTable = keyObjectStore.Table<string>("myTable"))
            {

                myTable.Empty();

                var firstId = myTable.Insert("foo");
                var secondId = myTable.Insert("bar");
                var thirdId = myTable.Insert("THREE");

                var second = myTable.Select(secondId);
                Assert.AreEqual("bar", second);

                myTable.Delete(secondId);
                var secondIsDeleted = myTable.Select(secondId);

                Assert.IsNull(secondIsDeleted);

                var all = myTable.All();

                Assert.AreEqual(2, all.Count());
            }
        }
开发者ID:joeriks,项目名称:UmbracoFuncHost,代码行数:27,代码来源:KeyObjectStoreTest.cs



注:本文中的PetaPoco.Database类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PgHdr类代码示例发布时间:2022-05-24
下一篇:
C# Pet类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap