Load all objects of specific type from Ravendb and use include to load related documents












1















I am trying to load all the elements of type Cause from ravenDB and also to Include related documents contained in each specific object (in order to improve performance). For instance, I am trying to mix the following two calls together:



To load all documents:



 _session.Advanced.DocumentQuery<Cause>()
.WhereEquals(x => x.IsDeleted, false)
.WaitForNonStaleResultsAsOfLastWrite()
.ToArray();


To Include related documents into the call:



_session.Include<Cause>(x => x.ValueIds)
.Load(idCause);


Does anyone know how I could approach this problem?



Edit For anyone stumbling on this problem one possible solution is as follows:



_session.Query<Cause>()
.Include(x => x.ValueIds)
.Where(x => x.IsDeleted == false);


Edit 2
I encountered a different problem but it is related to the above. If I wanted to add an additional element into the Include call, does anyone know how I could achieve this? I tried the following, but I don't think it is the proper way of doing this because additional calls to the database are being made:



_session.Query<Cause>()
.Include(x => x.ValueIds)
.Include(x => x.GroupIds)
.Where(x => x.IsDeleted == false);









share|improve this question





























    1















    I am trying to load all the elements of type Cause from ravenDB and also to Include related documents contained in each specific object (in order to improve performance). For instance, I am trying to mix the following two calls together:



    To load all documents:



     _session.Advanced.DocumentQuery<Cause>()
    .WhereEquals(x => x.IsDeleted, false)
    .WaitForNonStaleResultsAsOfLastWrite()
    .ToArray();


    To Include related documents into the call:



    _session.Include<Cause>(x => x.ValueIds)
    .Load(idCause);


    Does anyone know how I could approach this problem?



    Edit For anyone stumbling on this problem one possible solution is as follows:



    _session.Query<Cause>()
    .Include(x => x.ValueIds)
    .Where(x => x.IsDeleted == false);


    Edit 2
    I encountered a different problem but it is related to the above. If I wanted to add an additional element into the Include call, does anyone know how I could achieve this? I tried the following, but I don't think it is the proper way of doing this because additional calls to the database are being made:



    _session.Query<Cause>()
    .Include(x => x.ValueIds)
    .Include(x => x.GroupIds)
    .Where(x => x.IsDeleted == false);









    share|improve this question



























      1












      1








      1


      1






      I am trying to load all the elements of type Cause from ravenDB and also to Include related documents contained in each specific object (in order to improve performance). For instance, I am trying to mix the following two calls together:



      To load all documents:



       _session.Advanced.DocumentQuery<Cause>()
      .WhereEquals(x => x.IsDeleted, false)
      .WaitForNonStaleResultsAsOfLastWrite()
      .ToArray();


      To Include related documents into the call:



      _session.Include<Cause>(x => x.ValueIds)
      .Load(idCause);


      Does anyone know how I could approach this problem?



      Edit For anyone stumbling on this problem one possible solution is as follows:



      _session.Query<Cause>()
      .Include(x => x.ValueIds)
      .Where(x => x.IsDeleted == false);


      Edit 2
      I encountered a different problem but it is related to the above. If I wanted to add an additional element into the Include call, does anyone know how I could achieve this? I tried the following, but I don't think it is the proper way of doing this because additional calls to the database are being made:



      _session.Query<Cause>()
      .Include(x => x.ValueIds)
      .Include(x => x.GroupIds)
      .Where(x => x.IsDeleted == false);









      share|improve this question
















      I am trying to load all the elements of type Cause from ravenDB and also to Include related documents contained in each specific object (in order to improve performance). For instance, I am trying to mix the following two calls together:



      To load all documents:



       _session.Advanced.DocumentQuery<Cause>()
      .WhereEquals(x => x.IsDeleted, false)
      .WaitForNonStaleResultsAsOfLastWrite()
      .ToArray();


      To Include related documents into the call:



      _session.Include<Cause>(x => x.ValueIds)
      .Load(idCause);


      Does anyone know how I could approach this problem?



      Edit For anyone stumbling on this problem one possible solution is as follows:



      _session.Query<Cause>()
      .Include(x => x.ValueIds)
      .Where(x => x.IsDeleted == false);


      Edit 2
      I encountered a different problem but it is related to the above. If I wanted to add an additional element into the Include call, does anyone know how I could achieve this? I tried the following, but I don't think it is the proper way of doing this because additional calls to the database are being made:



      _session.Query<Cause>()
      .Include(x => x.ValueIds)
      .Include(x => x.GroupIds)
      .Where(x => x.IsDeleted == false);






      database ravendb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 8:41







      Razvan

















      asked Jan 3 at 7:54









      RazvanRazvan

      749




      749
























          1 Answer
          1






          active

          oldest

          votes


















          3














          1) In addition to the solution you mention in 'Edit1',
          you can also use:



          var results = session.Advanced.DocumentQuery<Cause>()
          .Include(x => x.ValueIds)
          .WhereEquals(x => x.IsDeleted, false)
          .ToList();




          2) Using Multiple Includes on the same operation (as you are doing in 'Edit2') is correct.

          See: https://github.com/ravendb/book/blob/v4.0/Ch02/Ch02.md#includes






          share|improve this answer


























          • I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

            – Razvan
            Jan 3 at 9:00













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018333%2fload-all-objects-of-specific-type-from-ravendb-and-use-include-to-load-related-d%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          1) In addition to the solution you mention in 'Edit1',
          you can also use:



          var results = session.Advanced.DocumentQuery<Cause>()
          .Include(x => x.ValueIds)
          .WhereEquals(x => x.IsDeleted, false)
          .ToList();




          2) Using Multiple Includes on the same operation (as you are doing in 'Edit2') is correct.

          See: https://github.com/ravendb/book/blob/v4.0/Ch02/Ch02.md#includes






          share|improve this answer


























          • I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

            – Razvan
            Jan 3 at 9:00


















          3














          1) In addition to the solution you mention in 'Edit1',
          you can also use:



          var results = session.Advanced.DocumentQuery<Cause>()
          .Include(x => x.ValueIds)
          .WhereEquals(x => x.IsDeleted, false)
          .ToList();




          2) Using Multiple Includes on the same operation (as you are doing in 'Edit2') is correct.

          See: https://github.com/ravendb/book/blob/v4.0/Ch02/Ch02.md#includes






          share|improve this answer


























          • I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

            – Razvan
            Jan 3 at 9:00
















          3












          3








          3







          1) In addition to the solution you mention in 'Edit1',
          you can also use:



          var results = session.Advanced.DocumentQuery<Cause>()
          .Include(x => x.ValueIds)
          .WhereEquals(x => x.IsDeleted, false)
          .ToList();




          2) Using Multiple Includes on the same operation (as you are doing in 'Edit2') is correct.

          See: https://github.com/ravendb/book/blob/v4.0/Ch02/Ch02.md#includes






          share|improve this answer















          1) In addition to the solution you mention in 'Edit1',
          you can also use:



          var results = session.Advanced.DocumentQuery<Cause>()
          .Include(x => x.ValueIds)
          .WhereEquals(x => x.IsDeleted, false)
          .ToList();




          2) Using Multiple Includes on the same operation (as you are doing in 'Edit2') is correct.

          See: https://github.com/ravendb/book/blob/v4.0/Ch02/Ch02.md#includes







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 10:26

























          answered Jan 3 at 8:53









          DanielleDanielle

          4801515




          4801515













          • I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

            – Razvan
            Jan 3 at 9:00





















          • I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

            – Razvan
            Jan 3 at 9:00



















          I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

          – Razvan
          Jan 3 at 9:00







          I am sorry but I wasn't very clear in my question. I am trying to load multiple entities at once that are of different types, that is the reason why I am doing two different includes at once. The approach you suggested in the edit seems to refer to the case when the entities are of the same type. Thanks for your answer!

          – Razvan
          Jan 3 at 9:00






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018333%2fload-all-objects-of-specific-type-from-ravendb-and-use-include-to-load-related-d%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas