本文整理汇总了C#中DataBase.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# DataBase.Insert方法的具体用法?C# DataBase.Insert怎么用?C# DataBase.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBase
的用法示例。
在下文中一共展示了DataBase.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//O ../ significa voltar no diretório ....fiz a função em C++ talvez podemos usar isso para buscas.
//[DllImport("../../Reader/bin/debug/Reader.dll")]
//private static extern int main();
static void Main(string[] args)
{
// main();
test u = new test("joseh", 12, 1.50);
u.addElement();
//DBFormatter bformatter = new DBFormatter();
//bformatter.Serialize(u);
//Stream streamr = File.Open("test", FileMode.Open, FileAccess.Read, FileShare.None);
//DBFormatter bformatter = new DBFormatter();
//Guid guid = new Guid("5ca72477-2a44-4177-8d13-609259a5453b");
//object k = bformatter.Deserialize(streamr, guid);
//if (k != null)
//{
// test p = (test)k;
// Console.WriteLine("nome: " + p.Nome);
// Console.WriteLine("idade: " + p.Idade);
// foreach (var s in p.Lista)
// {
// test2 t = (test2)s;
// Console.WriteLine(t.Nome);
// }
// Console.ReadKey();
//}
DataBase db = new DataBase();
db.CreateDataBase("teste");
db.UseDataBase("teste");
db.Insert(u);
}
示例2: AddTagsToPost
public void AddTagsToPost(Int64 postId, List<TagData> tagList)
{
using (var db = new DataBase())
{
foreach (var tag in tagList)
{
db.Insert(new TagPostData
{
PostId = postId,
TagId = tag.Id
});
}
}
}
示例3: TryToVote
public bool TryToVote(PostVotingData instance)
{
using (var db = new DataBase())
{
db.BeginTransaction();
var post = db.PostTable.FirstOrDefault(i => i.Id == instance.PostId);
if (post == null)
return false;
//Update vote
var copyVote = db.PostVotingTable.FirstOrDefault(i => i.PostId == instance.PostId && i.UserId == instance.UserId);
if (copyVote != null)
{
//Delete opposite vote
if (copyVote.IsVoteUp != instance.IsVoteUp)
{
db.PostVotingTable.Where(i => i.PostId == copyVote.PostId && i.UserId == copyVote.UserId).Delete();
}
else
{
//User already have such vote
return false;
}
}
else
{
db.Insert(instance);
}
//Update post ratig
var postRating = post.Rating + (instance.IsVoteUp ? 1 : -1);
db.PostTable.Where(i => i.Id == instance.PostId).Set(i => i.Rating, postRating).Update();
db.CommitTransaction();
return true;
}
}