Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-6953

.NET SDK docs need example of using the result of a Get()

    XMLWordPrintable

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • sdk3.2-backlog
    • sdk
    • None

    Description

      As a non-C# guy, trying to use C#, I ran into troubles trying to figure out how to use the result of the collection.GetAsync() method. An explicit code example that's right in the SDK docs would help.

      Perhaps it's like the following (NOTE: I am guessing! Not validated / not sure)...
      {{
      var result = await collection.GetAsync(“post-1234");

      var title = getResult.ContentAs<dynamic>()["title"];

      /* title == "My Latest Blog Post" */
      }}

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            jmorris Jeff Morris added a comment - - edited

            If you need to call `ContentAs<T>()` in SDK 3 per RFC:

            The Typed returned by as `dynamic` is a `JObject`, so you need to follow its syntax:

            result.ContentAs<dynamic>().title.Value;
            

            If `T` is a POCO (like a POJO):

            public class Post
            {
                public string Title {get;set;}
                ...
            }
            result.ContentAs<Post>().Title;
            

            jmorris Jeff Morris added a comment - - edited If you need to call `ContentAs<T>()` in SDK 3 per RFC: The Typed returned by as `dynamic` is a `JObject`, so you need to follow its syntax: result.ContentAs<dynamic>().title.Value; If `T` is a POCO (like a POJO): public class Post { public string Title {get;set;} ... } result.ContentAs<Post>().Title;

            Hakim Cassimally assigning this to you as you are working on a sample application. Probably want to consider this comment as well.

            arun.vijayraghavan Arun Vijayraghavan (Inactive) added a comment - Hakim Cassimally  assigning this to you as you are working on a sample application. Probably want to consider this comment as well.

            People

              hakim.cassimally Hakim Cassimally
              steve Steve Yen
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty