3

I create a simple insert operation to add the document to the server. My problem is the server has the id and empty content. I create all the staff by tutorial from Source code

this is source code

var document = new Document<Person>
{
  Id = "P1",
  Content = new Person
  {
      FirstName = "John",
      LastName = "Adams",
      Age = 21
  }
};

var result = bucket.Insert(document);
if (result.Success)
{
  Console.WriteLine("Inserted document '{0}'", document.Id);
}

that's mine (in a picture I show what I get in a server)

IBucket bucket = await ClusterHelper.GetBucketAsync("new_bucket");

var document = new Document<Person>
        {
            Id = "P1",
            Content = new Person
            {
                Name = "John",
                Surname = "Adams",
                Age = 21
            }
        };

        var result = await bucket.InsertAsync(document);
        if (result.Success)
            Console.WriteLine("Inserted document '{0}'", document.Id);
        else
            Console.WriteLine("Error this document exist");

enter image description here

I would like to know, Why it doesn't work with an object person? Why it saves empty content? (I take the example from source code, maybe I did something wrong?

Edit

public class Person
{
    internal string Name { get; set; }
    internal string Surname { get; set; }
    internal int Age { get; set; }
}

Some interesting thing if I write the

var document = new Document<dynamic>
        {
            Id = "dynamic",
            Content = new
            {
                Name = "John",
                Surname = "Adams",
                Age = 21
            }
        };

I take the content but it isn't comfortable( just my meaning)

enter image description here

Interesting but GET, UPDATE has the same problem. Get<Person> always returns Null value. WHY couchbase have that strange behavior?

Important

The problem with access modification internal need to use only public! however why? does anyone have an idea?

Andrey
  • 147
  • 3
  • 12
  • I'm a little confused. It works as you expect when using `dynamic`, but not when using `Person`? – Matthew Groves Aug 14 '19 at 15:34
  • I found the problem. Do you know why it doesn't work with access modification `Internal`, just `public`, for me it interesting and strange. – Andrey Aug 15 '19 at 08:59
  • Your `Person` class is internal? – Matthew Groves Aug 15 '19 at 12:47
  • I added it into the question, you can watch it after **Edit** part (I forgot to change the public class to internal, but if I have any field with internal which I wanna send to the server, it saves empty string – Andrey Aug 15 '19 at 13:39
  • Okay, I think this might be because of the way the Json serializer works. Check out this question: https://stackoverflow.com/questions/26873755/json-serializer-object-with-internal-properties – Matthew Groves Aug 15 '19 at 17:20
  • Yes, you were right, could you write the answer and I will mark it. Maybe in the future, this information would help someone like me now. – Andrey Aug 16 '19 at 06:27

0 Answers0