本文整理汇总了C#中ODatabase.UpdateRecord方法的典型用法代码示例。如果您正苦于以下问题:C# ODatabase.UpdateRecord方法的具体用法?C# ODatabase.UpdateRecord怎么用?C# ODatabase.UpdateRecord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODatabase
的用法示例。
在下文中一共展示了ODatabase.UpdateRecord方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestPocoCreateAndUpdateAndLoadRecord
public void TestPocoCreateAndUpdateAndLoadRecord()
{
using (ODatabase database = new ODatabase(_hostname, _port, _databaseName, ODatabaseType.Document, _username, _password))
{
TestClass foo = new TestClass();
// basic types
foo.IsBool = true;
foo.ByteNumber = 22;
foo.ShortNumber = 22222;
foo.IntNumber = 12345678;
foo.LongNumber = 1234567890123;
foo.FloatNumber = 3.14f;
foo.DoubleNumber = 12343.23442;
foo.DecimalNumber = new Decimal(1234567.890);
foo.DateTime = DateTime.Now;
foo.String = "Bra\"vo \\ asdf";
// collections
foo.StringArray = new string[] { "str elem 1", "str elem 2", "str elem 3" };
foo.StringList = new List<string>() { "str list elem 1", "str list elem 2", "str list elem 3" };
// embedded document
foo.NestedClass = new TestNestedClass();
foo.NestedClass.NestedString = "test nested string";
foo.NestedClass.StringArray = new string[] { "str elem 1", "str elem 2", "str elem 3" };
foo.NestedClass.StringList = new List<string>() { "str list elem 1", "str list elem 2", "str list elem 3" };
// collection of embedded documents
foo.ObjectList = new List<TestNestedClass>();
foo.ObjectList.Add(new TestNestedClass()
{
NestedString = "test embedded doc 1 string",
StringArray = new string[] { "str elem 1", "str elem 2", "str elem 3" },
StringList = new List<string>() { "str list elem 1", "str list elem 2", "str list elem 3" }
});
foo.ObjectList.Add(new TestNestedClass()
{
NestedString = "test embedded doc2 string",
StringArray = new string[] { "str elem 11", "str elem 12", "str elem 13" },
StringList = new List<string>() { "str list elem 11", "str list elem 12", "str list elem 13" }
});
// single and collection of ORIDs
foo.SingleOrid = new ORID("#10:1334");
foo.OridList = new List<ORID>();
foo.OridList.Add(new ORID("#11:123"));
foo.OridList.Add(new ORID("#22:12345"));
foo.OridList.Add(new ORID("#33:1234567"));
ORecord recordCreated = database.CreateRecord("TestClass", foo);
TestClass fooRetrieved = database.LoadRecord<TestClass>(recordCreated.ORID);
string newStringValue = "new value of string after update";
fooRetrieved.String = newStringValue;
foo.String = newStringValue;
int newVersion = database.UpdateRecord(recordCreated.ORID, fooRetrieved);
Assert.IsTrue(newVersion == (recordCreated.Version + 1));
fooRetrieved = null;
fooRetrieved = database.LoadRecord<TestClass>(recordCreated.ORID);
// basic types
Assert.IsTrue(fooRetrieved.Null == null);
Assert.IsTrue(fooRetrieved.IsBool == foo.IsBool);
Assert.IsTrue(fooRetrieved.ByteNumber == foo.ByteNumber);
Assert.IsTrue(fooRetrieved.ByteNumber == foo.ByteNumber);
Assert.IsTrue(fooRetrieved.IntNumber == foo.IntNumber);
Assert.IsTrue(fooRetrieved.LongNumber == foo.LongNumber);
Assert.IsTrue(fooRetrieved.FloatNumber == foo.FloatNumber);
Assert.IsTrue(fooRetrieved.DoubleNumber == foo.DoubleNumber);
Assert.IsTrue(fooRetrieved.DecimalNumber == foo.DecimalNumber);
Assert.IsTrue(fooRetrieved.DateTime.ToString() == foo.DateTime.ToString());
Assert.IsTrue(fooRetrieved.String == foo.String);
// collections
Assert.IsTrue(fooRetrieved.StringArray.Length == foo.StringArray.Length);
Assert.IsTrue(fooRetrieved.StringArray[0] == foo.StringArray[0]);
Assert.IsTrue(fooRetrieved.StringArray[1] == foo.StringArray[1]);
Assert.IsTrue(fooRetrieved.StringArray[2] == foo.StringArray[2]);
Assert.IsTrue(fooRetrieved.StringList.Count == foo.StringList.Count);
Assert.IsTrue(fooRetrieved.StringList[0] == foo.StringList[0]);
Assert.IsTrue(fooRetrieved.StringList[1] == foo.StringList[1]);
Assert.IsTrue(fooRetrieved.StringList[2] == foo.StringList[2]);
// embedded document
Assert.IsTrue(fooRetrieved.NestedClass.NestedString == foo.NestedClass.NestedString);
Assert.IsTrue(fooRetrieved.NestedClass.StringArray.Length == foo.NestedClass.StringArray.Length);
Assert.IsTrue(fooRetrieved.NestedClass.StringArray[0] == foo.NestedClass.StringArray[0]);
Assert.IsTrue(fooRetrieved.NestedClass.StringArray[1] == foo.NestedClass.StringArray[1]);
Assert.IsTrue(fooRetrieved.NestedClass.StringArray[2] == foo.NestedClass.StringArray[2]);
Assert.IsTrue(fooRetrieved.NestedClass.StringList.Count == foo.NestedClass.StringList.Count);
Assert.IsTrue(fooRetrieved.NestedClass.StringList[0] == foo.NestedClass.StringList[0]);
Assert.IsTrue(fooRetrieved.NestedClass.StringList[1] == foo.NestedClass.StringList[1]);
Assert.IsTrue(fooRetrieved.NestedClass.StringList[2] == foo.NestedClass.StringList[2]);
// collection of embedded documents
Assert.IsTrue(fooRetrieved.ObjectList.Count == foo.ObjectList.Count);
Assert.IsTrue(fooRetrieved.ObjectList[0].NestedString == foo.ObjectList[0].NestedString);
Assert.IsTrue(fooRetrieved.ObjectList[0].StringArray.Length == foo.ObjectList[0].StringArray.Length);
//.........这里部分代码省略.........