2015-01-07 1 views
2

.Net 개발자이고 현재 ArangoDB에서 탐색 중입니다. 나는 arangod 웹 사용자 인터페이스와 arangod를 가지고 놀았으며 코딩의 세부 사항을 탐구 할 때까지이 NoSql을 매우 좋아한다. .Net 드라이버가 제대로 작동하지 않습니다. 간단한 CRUD 조작에도. 여기에 문제가 있습니다..Net의 ArangoDB 업데이트 작업

ArangoClient.AddConnection("127.0.0.1", 8529, false, "Sample", "Sample"); 

var db = new ArangoDatabase("Sample"); 

string collectionName = "MyTestCollection"; 
var collection = new ArangoCollection(); 
collection.Name = collectionName; 
collection.Type = ArangoCollectionType.Document; 

if (db.Collection.Get(collectionName) == null) 
{ 
    db.Collection.Create(collection); 
} 

var employee = new Employee(); 

employee.Id = "1234"; 
employee.Name = "My Name"; 
employee.Salary = 33333; 
employee.DateOfBirth = new DateTime(1979, 7, 22); 

db.Document.Create<Employee>("MyTestCollection", employee); 

employee.Name = "Tan"; 
db.Document.Update(employee); 

db.Document.Update(employee)에 대해 오류가 발생했습니다. 오류 메시지 : '_id'필드가 존재하지 않습니다.

그런데 이상하게 생각되지만 _id 필드를 추가하려고하면 다른 오류 메시지가 표시됩니다.

Arango.Client.ArangoException : ArangoDB responded with error code BadRequest: 
expecting PATCH /_api/document/<document-handle> [error number 400] 
    at Arango.Client.Protocol.DocumentOperation.Patch(Document document, Boolean waitForSync, String revision) 
    at Arango.Client.ArangoDocumentOperation.Update[T](T genericObject, Boolean waitForSync, String revision) ... 

나는 전혀 단서가없고 더 진행하는 방법을 모르겠어요. 어떤 도움을 많이 주시면 감사하겠습니다. 감사.

답변

4

이것은 위의 스 니펫에 포함되어 있지 않은 Employee 클래스의 정의가 원인 일 가능성이 큽니다.

문서는 _id, _key_rev 같은 특수 시스템 속성을 가지고 컬렉션의 문서를 식별합니다. 이러한 특성은 명시 적으로 사용되지 않더라도 .NET 클래스의 속성에 매핑되어야합니다. 따라서 클래스의 속성 중 하나는 "Identity"로, 하나는 "Key"로, 다른 하나는 "Revision"으로 태그를 지정해야합니다. 여기에 작동합니다 예를 들어 클래스 정의는 다음과 같습니다

public class Employee 
{ 
    /* this will map the _id attribute from the database to ThisIsId property */ 
    [ArangoProperty(Identity = true)] 
    public string ThisIsId { get; set; } 

    /* this will map the _key attribute from the database to the Id property */ 
    [ArangoProperty(Key = true)] 
    public string Id { get; set; } 

    /* here is _rev */   
    [ArangoProperty(Revision = true)] 
    public string ThisIsRevision { get; set; } 

    public DateTime DateOfBirth { get; set; } 
    public string Name { get; set; } 
    public int Salary { get; set; } 

    public Employee() 
    { 
    } 
} 

ThisIsId 속성은 자동으로 할당 _id 값을 포함하며, 또한 나중에 쉽게 문서를 검색하는 데 사용할 수 있습니다 :

var employeeFromDatabase = db.Document.Get<Employee>(employee.ThisIsId); 

당신의 수를 코스 이름을 원하는대로 바꿉니다.

+0

감사합니다 stj.It .Net 드라이버에 대한 설명서가 많지 않으므로 제대로 이해하기 어렵습니다. – user1003132