本文整理汇总了C#中PetaPoco.Database.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# PetaPoco.Database.Insert方法的具体用法?C# PetaPoco.Database.Insert怎么用?C# PetaPoco.Database.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PetaPoco.Database
的用法示例。
在下文中一共展示了PetaPoco.Database.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: InitDataBase
public void InitDataBase(string connectionString)
{
var db = new PetaPoco.Database(connectionString, "System.Data.SqlClient");
db.Execute(Const.DBCreateScript);
foreach (var province in ProvinceData.GetProvinces())
{
db.Insert("Province", "Id", new{Name = province.Name, Code = province.Code});
}
var provinces = db.Query<dynamic>(@"SELECT *
from Province").ToList();
BulkUploadToSql bulk =
BulkUploadToSql.Load(
HomeData.GetHomes()
.Select(
i =>
new Bulk.Home
{
AddTime = DateTime.Now,
BuildYear = i.BuildYear,
City = i.City,
Description = i.Description,
Price = i.Price,
Surface = i.Surface,
ProvinceId = provinces.First(j => j.Code == i.HomeProvince.Code).Id,
}), "Home", 10000, connectionString);
bulk.Flush();
}
示例3: 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.");
}
}
示例4: AddForum
public static int AddForum(Models.Forums form)
{
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
int id = Convert.ToInt32(db.Insert(form));
return id;
}
}
示例5: CreatUser
public static bool CreatUser(User user)
{
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
user.Password = XBBS.Core.Utils.MD5(user.Password);
return db.Insert(user) != null;
}
}
示例6: Post
public IHttpActionResult Post([FromUri] string id, [FromBody]Entities.Logs logs)
{
var db = new PetaPoco.Database("AGSoftware");
logs.EventDateTime = System.DateTime.Now;
logs.UserName = this.User.Identity.Name;
db.Insert(logs);
return Ok();
}
示例7: BasicCRUD
public void BasicCRUD()
{
var db = new PetaPoco.Database("Chinook");
var newID = db.Insert(new Artist
{
Name = "Woot"
});
var acdcnew = db.Update(new Artist { ArtistId = 1, Name = "AC/DC Blah" });
var acdc = db.Update(new Artist { ArtistId = 1, Name = "AC/DC" });
}
示例8: Post
public IHttpActionResult Post([FromUri] string id, [FromBody] Entities.StorytimeSeries storytimeseries)
{
var db = new PetaPoco.Database("AGSoftware");
storytimeseries.StorytimeId = int.Parse(id);
storytimeseries.DateCreated = System.DateTime.Now;
storytimeseries.UserId = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name);
storytimeseries.UsersNotified = false;
db.Insert(storytimeseries);
return Ok(storytimeseries);
}
示例9: POST
public object POST([FromBody] Novedad item) {
try {
var db = new PetaPoco.Database("jlapc");
if (item.NovedadID == 0) {
db.Insert(item);
} else {
db.Update(item);
}
return (new JsonResult() { Data = new { ok = true, error = "" }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }).Data;
} catch (Exception e) {
return (new JsonResult() { Data = new { ok = false, error = e.Message }, JsonRequestBehavior = JsonRequestBehavior.AllowGet }).Data;
}
}
示例10: AddComment
public static bool AddComment(Models.Comment comment)
{
var f = GetForum(comment.FId);
if (f == null) return false;
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
f.LastReply = DateTime.Now;
f.Comments++;
f.Ruid = comment.UId;
db.Update(f, new string[] { "lastreply", "comments","ruid" });
return db.Insert(comment) != null;
}
}
示例11: create
public string create(HoiVien hv)
{
var db = new PetaPoco.Database("MyConnection");
hv.APK = Guid.NewGuid();
try { db.Insert(hv); }
catch (Exception e)
{
if (e.Message.Contains("Violation of PRIMARY KEY"))
{
return "pk";
}
return e.ToString();
}
return "ok";
}
示例12: button2_Click
private void button2_Click(object sender, EventArgs e)
{
// Create a PetaPoco database object
var db = new PetaPoco.Database("sqlite");
foo foo = new foo();
foo.name = "PetaPoco Insert Test";
try
{
db.Insert("foo", "Id", foo);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message + Environment.NewLine + ex.StackTrace);
}
this.fooQuery1.Refresh();
}
示例13: AddTarg
/// <summary>
/// 插入标签
/// </summary>
/// <param name="targTitle"></param>
/// <param name="fid"></param>
public static void AddTarg(string targTitle, int fid)
{
using (PetaPoco.Database db = new PetaPoco.Database("sqlconnection"))
{
Models.Targs tag = db.SingleOrDefault<Models.Targs>("WHERE [email protected]", targTitle);
if (tag == null)
{
tag = new Models.Targs();
tag.Forums = fid;
tag.Title = targTitle;
db.Save(tag);
}
Models.TargsRelation tagr = new Models.TargsRelation();
tagr.TagID = tag.TagID;
tagr.ForumsId = fid;
db.Insert(tagr);
}
}
示例14: AddNewGroupUsers
public IHttpActionResult AddNewGroupUsers([FromBody]Entities.UserGroup usergroup)
{
var db = new PetaPoco.Database("AGSoftware");
var b = db.SingleOrDefault<Entities.UserGroup>("Select * from UserGroup Where UserGroupId = @0", usergroup.UserGroupId);
Entities.UserGroupUser usergroupuser = null;
foreach (Entities.AspNetUsers user in usergroup.Users)
{
//todo see if there is a better way to do this with normalization and/or one connection.
var db2 = new PetaPoco.Database("AGSoftware");
usergroupuser = new Entities.UserGroupUser();
usergroupuser.UserGroupId = usergroup.UserGroupId;
usergroupuser.UserId = db2.SingleOrDefault<Entities.AspNetUsers>("Select Id from AspNetUsers where Id = @0", user.Id).Id; ;
db2.Insert(usergroupuser);
}
return Ok();
}
示例15: Post
public IHttpActionResult Post([FromUri] string id, [FromBody]Entities.UserGroup usergroup)
{
var db = new PetaPoco.Database("AGSoftware");
usergroup.UserId = Storytime.Providers.UserHelper.GetUserId(this.User.Identity.Name);
usergroup.DateCreated = System.DateTime.Now;
db.Insert(usergroup);
Entities.UserGroupUser usergroupuser = null;
foreach (Entities.AspNetUsers user in usergroup.Users)
{
//todo see if there is a better way to do this with normalization and/or one connection.
var db2 = new PetaPoco.Database("AGSoftware");
usergroupuser = new Entities.UserGroupUser();
usergroupuser.UserGroupId = usergroup.UserGroupId;
usergroupuser.UserId = db2.SingleOrDefault<Entities.AspNetUsers>("Select Id from AspNetUsers where Id = @0", user.Id).Id; ;
db2.Insert(usergroupuser);
}
return Ok(usergroup.UserGroupId);
}