本文整理汇总了C#中ODatabase.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# ODatabase.Insert方法的具体用法?C# ODatabase.Insert怎么用?C# ODatabase.Insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ODatabase
的用法示例。
在下文中一共展示了ODatabase.Insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldUpdateClassFromDocument
public void ShouldUpdateClassFromDocument()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
database
.Insert(document)
.Run();
database
.Insert(document)
.Run();
document
.SetField("bar", 54321)
.SetField("baz", "new baz value");
int documentsUpdated = database
.Update(document)
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<ODocument> documents = database
.Select()
.From("TestClass")
.ToList();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, document.OClassName);
Assert.AreEqual(documents[i].GetField<string>("foo"), document.GetField<string>("foo"));
Assert.AreEqual(documents[i].GetField<int>("bar"), document.GetField<int>("bar"));
Assert.AreEqual(documents[i].GetField<string>("baz"), document.GetField<string>("baz"));
}
}
}
}
示例2: ShouldUpdateClassFromObject
public void ShouldUpdateClassFromObject()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class<TestProfileClass>()
.Run();
TestProfileClass profile = new TestProfileClass();
profile.Name = "Johny";
database
.Insert(profile)
.Run();
database
.Insert(profile)
.Run();
profile.Name = "Julia";
profile.Surname = "Bravo";
int documentsUpdated = database
.Update(profile)
.Run();
Assert.AreEqual(documentsUpdated, 2);
List<TestProfileClass> documents = database
.Select()
.From<TestProfileClass>()
.ToList<TestProfileClass>();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, typeof(TestProfileClass).Name);
Assert.AreEqual(documents[i].Name, profile.Name);
Assert.AreEqual(documents[i].Surname, profile.Surname);
}
}
}
}
示例3: ProblemDeseralizingObjectWithDateTimeFields_31
public void ProblemDeseralizingObjectWithDateTimeFields_31()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
var startRecords = database.CountRecords;
// explicitly setting the timezone to UTC instead of the JVM default timezone
// FIXME: this is a work around for now
database.Command("ALTER DATABASE TIMEZONE UTC");
database.Create.Class<File>().Extends<OVertex>().CreateProperties().Run();
var dateTime = DateTime.UtcNow;
// OrientDB truncates milliseconds, so do so here for a proper comparison
dateTime = dateTime.AddTicks( - (dateTime.Ticks % TimeSpan.TicksPerSecond));
database.Insert(new File
{
Filename = "myfile",
Created = dateTime
}).Run();
var doc = database.Select().From<File>().ToList().First();
var file = doc.To<File>();
// FIXME: the time zone is off
Assert.That(file.Created, Is.EqualTo(dateTime));
var endRecords = database.CountRecords;
Assert.AreEqual(startRecords + 1, endRecords);
}
}
示例4: TestLoadWithFetchPlanNoLinks
public void TestLoadWithFetchPlanNoLinks()
{
using (var testContext = new TestDatabaseContext())
using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument()
.SetField("foo", "foo string value")
.SetField("bar", 12345);
ODocument insertedDocument = database
.Insert(document)
.Into("TestClass")
.Run();
var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
Assert.AreEqual("TestClass", loaded.OClassName);
Assert.AreEqual(document.GetField<string>("foo"), loaded.GetField<string>("foo"));
Assert.AreEqual(document.GetField<int>("bar"), loaded.GetField<int>("bar"));
Assert.AreEqual(insertedDocument.ORID, loaded.ORID);
}
}
示例5: ShouldInsertObject
public void ShouldInsertObject()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class<TestProfileClass>()
.Run();
TestProfileClass profile = new TestProfileClass();
profile.Name = "Johny";
profile.Surname = "Bravo";
TestProfileClass insertedDocument = database
.Insert(profile)
.Run<TestProfileClass>();
Assert.IsTrue(insertedDocument.ORID != null);
Assert.AreEqual(insertedDocument.OClassName, typeof(TestProfileClass).Name);
Assert.AreEqual(insertedDocument.Name, profile.Name);
Assert.AreEqual(insertedDocument.Surname, profile.Surname);
}
}
}
示例6: ShouldInsertDocumentInto
public void ShouldInsertDocumentInto()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument()
.SetField("foo", "foo string value")
.SetField("bar", 12345);
ODocument insertedDocument = database
.Insert(document)
.Into("TestClass")
.Run();
Assert.IsTrue(insertedDocument.ORID != null);
Assert.AreEqual(insertedDocument.OClassName, "TestClass");
Assert.AreEqual(insertedDocument.GetField<string>("foo"), document.GetField<string>("foo"));
Assert.AreEqual(insertedDocument.GetField<int>("bar"), document.GetField<int>("bar"));
}
}
}
示例7: ShouldSelectFromDocumentOClassNameQuery
public void ShouldSelectFromDocumentOClassNameQuery()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value1")
.Set("bar", 12345)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value2")
.Set("bar", 54321)
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
List<ODocument> documents = database
.Select()
.From(document)
.ToList();
Assert.AreEqual(documents.Count, 2);
for (int i = 0; i < documents.Count; i++)
{
Assert.IsTrue(documents[i].ORID != null);
Assert.AreEqual(documents[i].OClassName, document.OClassName);
Assert.IsTrue(documents[i].HasField("foo"));
Assert.IsTrue(documents[i].HasField("bar"));
}
}
}
}
示例8: ShouldSelectFromDocumentOrid
public void ShouldSelectFromDocumentOrid()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document1 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value1")
.Set("bar", 12345)
.Run();
ODocument document2 = database
.Insert()
.Into("TestClass")
.Set("foo", "foo string value2")
.Set("bar", 54321)
.Run();
List<ODocument> documents = database
.Select()
.From(document2)
.ToList();
Assert.AreEqual(documents.Count, 1);
for (int i = 0; i < documents.Count; i++)
{
Assert.AreEqual(documents[i].ORID, document2.ORID);
Assert.AreEqual(documents[i].OClassName, document2.OClassName);
Assert.AreEqual(documents[i].GetField<string>("foo"), document2.GetField<string>("foo"));
Assert.AreEqual(documents[i].GetField<int>("bar"), document2.GetField<int>("bar"));
}
}
}
}
示例9: PreparedQueryTest
public PreparedQueryTest()
{
_context = new TestDatabaseContext();
_database = new ODatabase(TestConnection.GlobalTestDatabaseAlias);
_database.Create.Class("Profile").Run();
var properties = new[]{
new {name="Michael",surname = "Blach"},
new {name="Shantaram",surname = "Gaikwad"},
new {name="Luca",surname = "Garulli"}
};
foreach (var item in properties)
{
_database.Insert()
.Into("Profile")
.Set("name", item.name)
.Set("surname", item.surname).Run();
}
}
示例10: ShouldCreateRecordContainingSingleQuote
public void ShouldCreateRecordContainingSingleQuote()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
if (!db.Schema.IsClassExist<TestClass>())
{
db.Create.Class<TestClass>().CreateProperties<TestClass>().Run();
}
db.Command("delete from TestClass");
var text = @"Jim'n";
var test = new TestClass() { SomeString = text };
db.Insert(test).Run();
var result = db.Select().From<TestClass>().ToList<TestClass>();
Assert.Equal(text, result.Single().SomeString);
}
}
示例11: ShouldInsertIntoClusterSet
public void ShouldInsertIntoClusterSet()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
database
.Create.Cluster("TestCluster", OClusterType.Physical)
.Run();
database.Command("alter class TestClass addcluster TestCluster");
ODocument insertedDocument = database
.Insert()
.Into("TestClass")
.Cluster("TestCluster")
.Set("foo", "foo string value")
.Set("bar", 12345)
.Run();
Assert.IsTrue(insertedDocument.ORID != null);
Assert.AreEqual(insertedDocument.OClassName, "TestClass");
Assert.AreEqual(insertedDocument.GetField<string>("foo"), "foo string value");
Assert.AreEqual(insertedDocument.GetField<int>("bar"), 12345);
}
}
}
示例12: using
public void GIVEN___EmployeeDictionaryType_class_with_common_data_type___WHEN___write_to_orientdb___THEN___should_be_able_to_read()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
using (var db = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
var employeeClassName = "EmployeeDictionaryType";
var clusterid = db.Create.Class(employeeClassName).Run();
var employee = new EmployeeDictionaryType();
employee.Id = Guid.NewGuid();
employee.Name = new Dictionary<string, string>();
employee.Name.Add("Andrew", "Andrew");
employee.Name.Add("Jack", "Jack");
employee.Ids = new Dictionary<Guid, Guid>();
employee.Ids.Add(Guid.NewGuid(), Guid.NewGuid());
employee.Ids.Add(Guid.NewGuid(), Guid.NewGuid());
employee.Age = new Dictionary<int, int>();
employee.Age.Add(1, 2);
employee.Age.Add(2, 4);
employee.Height = new Dictionary<short, short>();
employee.Height.Add(1, 2);
employee.Height.Add(2, 4);
employee.Tall = new Dictionary<long, long>();
employee.Tall.Add(1234567890123456789, 987654321098765432);
employee.Tall.Add(987654321098765432, 1234567890123456789);
employee.Childs = new Dictionary<int, EmployeeCommonType>();
employee.Childs.Add(1, new EmployeeCommonType() { Id = Guid.NewGuid() });
employee.Childs.Add(2, new EmployeeCommonType() { Id = Guid.NewGuid() });
employee.FavoriteColor = new Dictionary<Color, Color>();
employee.FavoriteColor.Add(Color.Red, Color.Red);
employee.FavoriteColor.Add(Color.Blue, Color.Blue);
var document = db.Insert(employee).Into(employeeClassName).Run();
var result = db.Query<EmployeeDictionaryType>("SELECT * FROM " + employeeClassName + " WHERE Id = '" + employee.Id + "'").SingleOrDefault();
Assert.Equal(employee.Id, result.Id);
Assert.True(result.Name.ContainsKey("Jack"));
Assert.True(result.Name.ContainsKey("Andrew"));
Assert.Equal(employee.Name["Jack"], result.Name["Jack"]);
Assert.Equal(employee.Name["Andrew"], result.Name["Andrew"]);
Assert.True(result.Ids.ContainsKey(employee.Ids.Keys.ToArray()[0]));
Assert.True(result.Ids.ContainsKey(employee.Ids.Keys.ToArray()[1]));
Assert.Equal(employee.Ids[employee.Ids.Keys.ToArray()[0]], result.Ids[employee.Ids.Keys.ToArray()[0]]);
Assert.Equal(employee.Ids[employee.Ids.Keys.ToArray()[1]], result.Ids[employee.Ids.Keys.ToArray()[1]]);
Assert.True(result.Age.ContainsKey(1));
Assert.True(result.Age.ContainsKey(2));
Assert.Equal(employee.Age[1], result.Age[1]);
Assert.Equal(employee.Age[2], result.Age[2]);
Assert.True(result.Height.ContainsKey(employee.Height.Keys.ToArray()[0]));
Assert.True(result.Height.ContainsKey(employee.Height.Keys.ToArray()[1]));
Assert.Equal(employee.Height[employee.Height.Keys.ToArray()[0]], result.Height[employee.Height.Keys.ToArray()[0]]);
Assert.Equal(employee.Height[employee.Height.Keys.ToArray()[1]], result.Height[employee.Height.Keys.ToArray()[1]]);
Assert.True(result.Tall.ContainsKey(employee.Tall.Keys.ToArray()[0]));
Assert.True(result.Tall.ContainsKey(employee.Tall.Keys.ToArray()[1]));
Assert.Equal(employee.Tall[employee.Tall.Keys.ToArray()[0]], result.Tall[employee.Tall.Keys.ToArray()[0]]);
Assert.Equal(employee.Tall[employee.Tall.Keys.ToArray()[1]], result.Tall[employee.Tall.Keys.ToArray()[1]]);
Assert.Equal(employee.Childs[1].Id, result.Childs[1].Id);
Assert.Equal(employee.Childs[2].Id, result.Childs[2].Id);
Assert.True(result.FavoriteColor.ContainsKey(Color.Red));
Assert.True(result.FavoriteColor.ContainsKey(Color.Blue));
Assert.Equal(employee.FavoriteColor[Color.Red], result.FavoriteColor[Color.Red]);
Assert.Equal(employee.FavoriteColor[Color.Blue], result.FavoriteColor[Color.Blue]);
}
}
示例13: TestLoadWithFetchPlanWithLinks
public void TestLoadWithFetchPlanWithLinks()
{
using (var testContext = new TestDatabaseContext())
using (var database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Extends("V")
.Run();
ODocument document = new ODocument()
.SetField("foo", "foo string value")
.SetField("bar", 12345);
ODocument insertedDocument = database
.Insert(document)
.Into("TestClass")
.Run();
for (int i = 0; i < 2; i++)
{
ODocument document2 = new ODocument()
.SetField("foo", "bar string value")
.SetField("bar", 23456);
ODocument insertedDocument2 = database
.Insert(document2)
.Into("TestClass")
.Run();
database.Create.Edge("E").From(insertedDocument).To(insertedDocument2).Run();
}
var loaded = database.Load.ORID(insertedDocument.ORID).FetchPlan("*:1").Run();
Assert.Equal("TestClass", loaded.OClassName);
Assert.Equal(document.GetField<string>("foo"), loaded.GetField<string>("foo"));
Assert.Equal(document.GetField<int>("bar"), loaded.GetField<int>("bar"));
Assert.Equal(insertedDocument.ORID, loaded.ORID);
}
}
示例14: ShouldUpdateRecordSet
public void ShouldUpdateRecordSet()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class("TestClass")
.Run();
ODocument document = new ODocument();
document.OClassName = "TestClass";
document
.SetField("foo", "foo string value")
.SetField("bar", 12345);
ODocument document1 = database
.Insert(document)
.Run();
ODocument document2 = database
.Insert(document)
.Run();
int documentsUpdated = database
.Update(document2.ORID)
.Set("bar", 54321)
.Set("baz", "new baz value")
.Run();
Assert.AreEqual(documentsUpdated, 1);
List<ODocument> documents = database
.Select()
.From("TestClass")
.Where("bar").Equals(54321)
.ToList();
Assert.AreEqual(documents.Count, 1);
Assert.AreEqual(documents[0].ORID, document2.ORID);
Assert.AreEqual(documents[0].OClassName, document2.OClassName);
Assert.AreEqual(documents[0].GetField<string>("foo"), document2.GetField<string>("foo"));
Assert.AreEqual(documents[0].GetField<int>("bar"), 54321);
Assert.AreEqual(documents[0].GetField<string>("baz"), "new baz value");
}
}
}
示例15: ShouldSelectToObjectList
public void ShouldSelectToObjectList()
{
using (TestDatabaseContext testContext = new TestDatabaseContext())
{
using (ODatabase database = new ODatabase(TestConnection.GlobalTestDatabaseAlias))
{
// prerequisites
database
.Create.Class<TestProfileClass>()
.Run();
TestProfileClass document1 = database
.Insert()
.Into<TestProfileClass>()
.Set("Name", "Johny")
.Set("Surname", "Bravo")
.Run<TestProfileClass>();
TestProfileClass document2 = database
.Insert()
.Into<TestProfileClass>()
.Set("Name", "Johny")
.Set("Surname", "Bravo")
.Run<TestProfileClass>();
List<TestProfileClass> documents = database
.Select()
.From<TestProfileClass>()
.ToList<TestProfileClass>();
Assert.AreEqual(documents.Count, 2);
Assert.AreEqual(documents[0].ORID, document1.ORID);
Assert.AreEqual(documents[0].OClassName, document1.OClassName);
Assert.AreEqual(documents[0].Name, document1.Name);
Assert.AreEqual(documents[0].Surname, document1.Surname);
Assert.AreEqual(documents[1].ORID, document2.ORID);
Assert.AreEqual(documents[1].OClassName, document2.OClassName);
Assert.AreEqual(documents[1].Name, document2.Name);
Assert.AreEqual(documents[1].Surname, document2.Surname);
}
}
}