本文整理汇总了C#中PetaPoco.Database类的典型用法代码示例。如果您正苦于以下问题:C# PetaPoco.Database类的具体用法?C# PetaPoco.Database怎么用?C# PetaPoco.Database使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PetaPoco.Database类属于命名空间,在下文中一共展示了PetaPoco.Database类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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("结束");
}
示例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();
}
}
示例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();
}
}
示例4: GetAllPages
public static List<Models.Page> GetAllPages()
{
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
return db.Query<Models.Page>("").ToList();
}
}
示例5: UpdateUser
public static void UpdateUser(Models.User u)
{
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
db.Save(u);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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
});
}
示例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);
}
示例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");
}
}
示例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();
}
示例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();
}
示例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);
}
}