本文整理汇总了C#中Mono.Data.Sqlite.Orm.Tests.OrmTestSession.InsertAll方法的典型用法代码示例。如果您正苦于以下问题:C# OrmTestSession.InsertAll方法的具体用法?C# OrmTestSession.InsertAll怎么用?C# OrmTestSession.InsertAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Data.Sqlite.Orm.Tests.OrmTestSession
的用法示例。
在下文中一共展示了OrmTestSession.InsertAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Skip
public void Skip()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
const int n = 100;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
select new TestObj
{
Order = i
};
TestObj[] objs = cq.ToArray();
int numIn = db.InsertAll(objs);
Assert.AreEqual(numIn, n, "Num inserted must = num objects");
TableQuery<TestObj> q = from o in db.Table<TestObj>()
orderby o.Order
select o;
TableQuery<TestObj> qs1 = q.Skip(1);
List<TestObj> s1 = qs1.ToList();
Assert.AreEqual(n - 1, s1.Count);
Assert.AreEqual(2, s1[0].Order);
TableQuery<TestObj> qs5 = q.Skip(5);
List<TestObj> s5 = qs5.ToList();
Assert.AreEqual(n - 5, s5.Count);
Assert.AreEqual(6, s5[0].Order);
}
示例2: QueriedStringArrayContainsTableColumnTest
public void QueriedStringArrayContainsTableColumnTest()
{
int n = 20;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n) select new TestObj { Name = i.ToString() };
var db = new OrmTestSession();
// temp stop trace for inputs
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
db.InsertAll(cq);
SqliteSession.Trace = true;
var tensArray = new[] { "0", "10", "20" };
var tensResult = from tens in db.Table<TestObj>()
where tensArray.Contains(tens.Name)
select tens.Name;
List<TestObj> more2 = (from all in db.Table<TestObj>()
where tensResult.Contains(all.Name)
select all).ToList();
Assert.AreEqual(2, more2.Count);
}
示例3: Contains
public void Contains()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
const int n = 20;
IEnumerable<TestObj> cq = from i in Enumerable.Range(1, n)
select new TestObj
{
Name = i.ToString(CultureInfo.InvariantCulture)
};
db.InsertAll(cq);
var tensq = new[] {"0", "10", "20"};
List<TestObj> tens = (from o in db.Table<TestObj>() where tensq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, tens.Count);
var moreq = new[] {"0", "x", "99", "10", "20", "234324"};
List<TestObj> more = (from o in db.Table<TestObj>() where moreq.Contains(o.Name) select o).ToList();
Assert.AreEqual(2, more.Count);
}
示例4: MultiplePkOperations
public void MultiplePkOperations()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
// insert
const int n = 10 , m= 5;
var objs = new TestObj[n * m];
for (int j = 0; j != n; ++j)
{
for (int i = 0; i != m; ++i)
{
objs[j * m + i] = new TestObj {Id = j, SubId = i, Text = "I am (" + j + "," + i + ")"};
}
}
int numIn = db.InsertAll(objs);
Assert.AreEqual(numIn, n * m, "Num inserted must = num objects");
var obj = db.Get<TestObj>(5, 3);
Assert.AreEqual(5, obj.Id);
Assert.AreEqual(3, obj.SubId);
Assert.AreEqual("I am (5,3)", obj.Text);
try
{
db.Insert(obj);
}
catch (SqliteException ex)
{
Assert.AreEqual(SQLiteErrorCode.Constraint, ex.ErrorCode);
}
// update
obj.Text = "I've been changed";
db.Update(obj);
db.Update<TestObj>("Text", "I've been changed also", 8, 2);
obj = db.Get<TestObj>(5, 3);
Assert.AreEqual("I've been changed", obj.Text);
obj = db.Get<TestObj>(8, 2);
Assert.AreEqual("I've been changed also", obj.Text);
db.UpdateAll<TestObj>("Text", "All changed");
IEnumerable<TestObj> q1 = from o in db.Table<TestObj>() select o;
foreach (TestObj o in q1)
Assert.AreEqual("All changed", o.Text);
TestObj[] q2 = (from o in db.Table<TestObj>() where o.SubId == 3 select o).ToArray();
Assert.AreEqual(10, q2.Length);
for (int i = 0; i != 10; ++i)
{
Assert.AreEqual(i, q2[i].Id);
}
object numCount = db.Table<TestObj>().Count();
Assert.AreEqual(numCount, objs.Length, "Num counted must = num objects");
// delete
obj = db.Get<TestObj>(8, 2);
db.Delete(obj);
try
{
var item = db.Get<TestObj>(8, 2);
Assert.Fail();
}
catch (InvalidOperationException)
{
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
db.Execute("delete from TestObj where SubId=2");
numCount = db.ExecuteScalar<int>("select count(*) from TestObj");
Assert.AreEqual(numCount, objs.Length - 10);
foreach (TestObj o in (from o in db.Table<TestObj>() select o))
Assert.AreNotEqual(2, o.SubId);
}
示例5: InsertALotPlain
public void InsertALotPlain()
{
var db = new OrmTestSession();
SqliteSession.Trace = false;
db.CreateTable<TestObjPlain>();
const int n = 10000;
IEnumerable<TestObjPlain> q = Enumerable.Range(1, n).Select(i => new TestObjPlain { Text = "I am" });
TestObjPlain[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
Assert.AreEqual(numIn, n, "Num inserted must = num objects");
TestObjPlain[] inObjs = db.Table<TestObjPlain>().ToArray();
foreach (TestObjPlain t in inObjs)
{
Assert.AreEqual("I am", t.Text);
}
int numCount = db.Table<TestObjPlain>().Count();
Assert.AreEqual(numCount, n, "Num counted must = num objects");
db.Close();
}
示例6: InsertAllWithinATransactionSucceeds
public void InsertAllWithinATransactionSucceeds()
{
var db = new OrmTestSession();
db.CreateTable<TestObj>();
var first = new TestObj { Text = "First" };
var second = new TestObj { Text = "Second" };
var third = new TestObj { Text = "Third" };
using (var trans = db.BeginTransaction())
{
var inObjs = db.InsertAll(new[] { first, second, third }, false);
trans.Commit();
}
Assert.AreEqual(3, db.Table<TestObj>().Count());
}
示例7: InsertALot
public void InsertALot()
{
var db = new OrmTestSession();
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
const int n = 10000;
IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(i => new TestObj { Text = "I am" });
TestObj[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
Assert.AreEqual(numIn, n, "Num inserted must = num objects");
TestObj[] inObjs = db.Table<TestObj>().ToArray();
for (int i = 0; i < inObjs.Length; i++)
{
Assert.AreEqual(i + 1, objs[i].Id);
Assert.AreEqual(i + 1, inObjs[i].Id);
Assert.AreEqual("I am", inObjs[i].Text);
}
int numCount = db.Table<TestObj>().Count();
Assert.AreEqual(numCount, n, "Num counted must = num objects");
db.Close();
}
示例8: NestedTransactionsTest
public void NestedTransactionsTest()
{
int oneTrans;
int nestedTrans;
// one transaction
using (var db = new OrmTestSession())
{
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
var start = Environment.TickCount;
const int n = 500*500;
IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
TestObj[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
oneTrans = Environment.TickCount - start;
}
// nested transactions
using (var db = new OrmTestSession())
{
SqliteSession.Trace = false;
db.CreateTable<TestObj>();
var start = Environment.TickCount;
using (var trans = db.BeginTransaction())
{
for (var i = 0; i < 500; ++i)
{
const int n = 500;
IEnumerable<TestObj> q = Enumerable.Range(1, n).Select(x => new TestObj {Text = "I am"});
TestObj[] objs = q.ToArray();
int numIn = db.InsertAll(objs);
}
trans.Commit();
}
nestedTrans = Environment.TickCount - start;
}
System.Diagnostics.Debug.WriteLine("Single tranasction: " + oneTrans);
System.Diagnostics.Debug.WriteLine("Nested tranasction: " + nestedTrans);
System.Diagnostics.Debug.WriteLine("Difference: " + Math.Abs(nestedTrans - oneTrans));
// this is a really dodgy test to use the execution time...
Assert.IsTrue(Math.Abs(oneTrans - nestedTrans) <= 100);
}