query with lambda expressions and one parameter is null











up vote
0
down vote

favorite












I want to do a query with lambda expression.
My database is a Cosmos DB.
I want to filter for two parameters and one of the two can be null.



For example i want to search for name and lastname and one of both is null.



This is that I am trying:



var result = this._client.CreateDocumentQuery<Person>(
UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
.Where((f) => f.Name == Name && f.LastName == lastName )
.AsEnumerable()
.ToList();









share|improve this question


























    up vote
    0
    down vote

    favorite












    I want to do a query with lambda expression.
    My database is a Cosmos DB.
    I want to filter for two parameters and one of the two can be null.



    For example i want to search for name and lastname and one of both is null.



    This is that I am trying:



    var result = this._client.CreateDocumentQuery<Person>(
    UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
    .Where((f) => f.Name == Name && f.LastName == lastName )
    .AsEnumerable()
    .ToList();









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to do a query with lambda expression.
      My database is a Cosmos DB.
      I want to filter for two parameters and one of the two can be null.



      For example i want to search for name and lastname and one of both is null.



      This is that I am trying:



      var result = this._client.CreateDocumentQuery<Person>(
      UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
      .Where((f) => f.Name == Name && f.LastName == lastName )
      .AsEnumerable()
      .ToList();









      share|improve this question













      I want to do a query with lambda expression.
      My database is a Cosmos DB.
      I want to filter for two parameters and one of the two can be null.



      For example i want to search for name and lastname and one of both is null.



      This is that I am trying:



      var result = this._client.CreateDocumentQuery<Person>(
      UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
      .Where((f) => f.Name == Name && f.LastName == lastName )
      .AsEnumerable()
      .ToList();






      c# lambda azure-cosmosdb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 9:15









      CMorillo

      32




      32
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          So this?



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where((f) => (f.Name == Name || (f.Name == null && f.LastName != null)) && (f.LastName == lastName || (f.LastName == null && f.Name != null))
          .AsEnumerable()
          .ToList();





          share|improve this answer





















          • This sentence is very long I want something sorter and more elegant
            – CMorillo
            Nov 12 at 10:39






          • 1




            Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
            – Nick Chapsas
            Nov 12 at 11:46












          • Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
            – SNO
            Nov 13 at 6:10










          • @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
            – Nick Chapsas
            Nov 13 at 9:49










          • Of course. You are right ;)
            – SNO
            Nov 13 at 11:30


















          up vote
          -1
          down vote













          try something like this:



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where(f => f.Name == $"{Name ?? f.Name}") &&
          f.LastName == $"{lastName ?? f.LastName}") )
          .AsEnumerable()
          .ToList();





          share|improve this answer























          • This will not work with CosmosDB as it doesn't support the like keyword.
            – Nick Chapsas
            Nov 12 at 9:46










          • @NickChapsas how about this one?
            – roozbeh S
            Nov 12 at 9:58










          • Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
            – Nick Chapsas
            Nov 12 at 10:00










          • So what do you think should happen if both are null?
            – roozbeh S
            Nov 12 at 10:35


















          up vote
          -1
          down vote













          Maybe you can work with IQueryable:



          IQueryable<Person> iPerson = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions);

          if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);
          if(lastName != null) iPerson = iPerson.Where(f => f.LastName == lastName)
          return iPerson.AsEnumerable().ToList();





          share|improve this answer























          • The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
            – Nick Chapsas
            Nov 12 at 9:23












          • @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
            – SNO
            Nov 12 at 14:49










          • Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
            – Nick Chapsas
            Nov 12 at 15:24










          • one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
            – SNO
            Nov 13 at 6:07













          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',
          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%2f53259013%2fquery-with-lambda-expressions-and-one-parameter-is-null%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          So this?



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where((f) => (f.Name == Name || (f.Name == null && f.LastName != null)) && (f.LastName == lastName || (f.LastName == null && f.Name != null))
          .AsEnumerable()
          .ToList();





          share|improve this answer





















          • This sentence is very long I want something sorter and more elegant
            – CMorillo
            Nov 12 at 10:39






          • 1




            Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
            – Nick Chapsas
            Nov 12 at 11:46












          • Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
            – SNO
            Nov 13 at 6:10










          • @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
            – Nick Chapsas
            Nov 13 at 9:49










          • Of course. You are right ;)
            – SNO
            Nov 13 at 11:30















          up vote
          0
          down vote



          accepted










          So this?



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where((f) => (f.Name == Name || (f.Name == null && f.LastName != null)) && (f.LastName == lastName || (f.LastName == null && f.Name != null))
          .AsEnumerable()
          .ToList();





          share|improve this answer





















          • This sentence is very long I want something sorter and more elegant
            – CMorillo
            Nov 12 at 10:39






          • 1




            Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
            – Nick Chapsas
            Nov 12 at 11:46












          • Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
            – SNO
            Nov 13 at 6:10










          • @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
            – Nick Chapsas
            Nov 13 at 9:49










          • Of course. You are right ;)
            – SNO
            Nov 13 at 11:30













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          So this?



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where((f) => (f.Name == Name || (f.Name == null && f.LastName != null)) && (f.LastName == lastName || (f.LastName == null && f.Name != null))
          .AsEnumerable()
          .ToList();





          share|improve this answer












          So this?



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where((f) => (f.Name == Name || (f.Name == null && f.LastName != null)) && (f.LastName == lastName || (f.LastName == null && f.Name != null))
          .AsEnumerable()
          .ToList();






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 9:20









          Nick Chapsas

          2,4561314




          2,4561314












          • This sentence is very long I want something sorter and more elegant
            – CMorillo
            Nov 12 at 10:39






          • 1




            Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
            – Nick Chapsas
            Nov 12 at 11:46












          • Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
            – SNO
            Nov 13 at 6:10










          • @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
            – Nick Chapsas
            Nov 13 at 9:49










          • Of course. You are right ;)
            – SNO
            Nov 13 at 11:30


















          • This sentence is very long I want something sorter and more elegant
            – CMorillo
            Nov 12 at 10:39






          • 1




            Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
            – Nick Chapsas
            Nov 12 at 11:46












          • Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
            – SNO
            Nov 13 at 6:10










          • @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
            – Nick Chapsas
            Nov 13 at 9:49










          • Of course. You are right ;)
            – SNO
            Nov 13 at 11:30
















          This sentence is very long I want something sorter and more elegant
          – CMorillo
          Nov 12 at 10:39




          This sentence is very long I want something sorter and more elegant
          – CMorillo
          Nov 12 at 10:39




          1




          1




          Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
          – Nick Chapsas
          Nov 12 at 11:46






          Sorry what? Are you expecting us to give you a complete elegant solution for a basic C# question? StackOverflow is not meant for that. You have the pointer, and a valid answer to your question. You can take it from there. A quick refactoring would be to extract the predicate to it's own function and reuse it.
          – Nick Chapsas
          Nov 12 at 11:46














          Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
          – SNO
          Nov 13 at 6:10




          Maybe this solution works, but I agree to CMorillo that this is not the cleaneast way and hard to maintain. Here, this solution wouldn't pass a code review.
          – SNO
          Nov 13 at 6:10












          @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
          – Nick Chapsas
          Nov 13 at 9:49




          @SNO It's not meant to. I think you are missing the point. SO doesn't provide complete solutions to requests. It provides answers to questions. Having a property called Name and another one LastName also wouldn't pass a code review. Same goes for single line if statements like this if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);, but that's not the point, is it?
          – Nick Chapsas
          Nov 13 at 9:49












          Of course. You are right ;)
          – SNO
          Nov 13 at 11:30




          Of course. You are right ;)
          – SNO
          Nov 13 at 11:30












          up vote
          -1
          down vote













          try something like this:



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where(f => f.Name == $"{Name ?? f.Name}") &&
          f.LastName == $"{lastName ?? f.LastName}") )
          .AsEnumerable()
          .ToList();





          share|improve this answer























          • This will not work with CosmosDB as it doesn't support the like keyword.
            – Nick Chapsas
            Nov 12 at 9:46










          • @NickChapsas how about this one?
            – roozbeh S
            Nov 12 at 9:58










          • Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
            – Nick Chapsas
            Nov 12 at 10:00










          • So what do you think should happen if both are null?
            – roozbeh S
            Nov 12 at 10:35















          up vote
          -1
          down vote













          try something like this:



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where(f => f.Name == $"{Name ?? f.Name}") &&
          f.LastName == $"{lastName ?? f.LastName}") )
          .AsEnumerable()
          .ToList();





          share|improve this answer























          • This will not work with CosmosDB as it doesn't support the like keyword.
            – Nick Chapsas
            Nov 12 at 9:46










          • @NickChapsas how about this one?
            – roozbeh S
            Nov 12 at 9:58










          • Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
            – Nick Chapsas
            Nov 12 at 10:00










          • So what do you think should happen if both are null?
            – roozbeh S
            Nov 12 at 10:35













          up vote
          -1
          down vote










          up vote
          -1
          down vote









          try something like this:



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where(f => f.Name == $"{Name ?? f.Name}") &&
          f.LastName == $"{lastName ?? f.LastName}") )
          .AsEnumerable()
          .ToList();





          share|improve this answer














          try something like this:



          var result = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions)
          .Where(f => f.Name == $"{Name ?? f.Name}") &&
          f.LastName == $"{lastName ?? f.LastName}") )
          .AsEnumerable()
          .ToList();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 10:34

























          answered Nov 12 at 9:31









          roozbeh S

          7961411




          7961411












          • This will not work with CosmosDB as it doesn't support the like keyword.
            – Nick Chapsas
            Nov 12 at 9:46










          • @NickChapsas how about this one?
            – roozbeh S
            Nov 12 at 9:58










          • Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
            – Nick Chapsas
            Nov 12 at 10:00










          • So what do you think should happen if both are null?
            – roozbeh S
            Nov 12 at 10:35


















          • This will not work with CosmosDB as it doesn't support the like keyword.
            – Nick Chapsas
            Nov 12 at 9:46










          • @NickChapsas how about this one?
            – roozbeh S
            Nov 12 at 9:58










          • Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
            – Nick Chapsas
            Nov 12 at 10:00










          • So what do you think should happen if both are null?
            – roozbeh S
            Nov 12 at 10:35
















          This will not work with CosmosDB as it doesn't support the like keyword.
          – Nick Chapsas
          Nov 12 at 9:46




          This will not work with CosmosDB as it doesn't support the like keyword.
          – Nick Chapsas
          Nov 12 at 9:46












          @NickChapsas how about this one?
          – roozbeh S
          Nov 12 at 9:58




          @NickChapsas how about this one?
          – roozbeh S
          Nov 12 at 9:58












          Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
          – Nick Chapsas
          Nov 12 at 10:00




          Still doesn't match his question. He said, "I want to filter for two parameters and one of the two can be null.". Your solution can work when both of them are null too.
          – Nick Chapsas
          Nov 12 at 10:00












          So what do you think should happen if both are null?
          – roozbeh S
          Nov 12 at 10:35




          So what do you think should happen if both are null?
          – roozbeh S
          Nov 12 at 10:35










          up vote
          -1
          down vote













          Maybe you can work with IQueryable:



          IQueryable<Person> iPerson = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions);

          if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);
          if(lastName != null) iPerson = iPerson.Where(f => f.LastName == lastName)
          return iPerson.AsEnumerable().ToList();





          share|improve this answer























          • The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
            – Nick Chapsas
            Nov 12 at 9:23












          • @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
            – SNO
            Nov 12 at 14:49










          • Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
            – Nick Chapsas
            Nov 12 at 15:24










          • one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
            – SNO
            Nov 13 at 6:07

















          up vote
          -1
          down vote













          Maybe you can work with IQueryable:



          IQueryable<Person> iPerson = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions);

          if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);
          if(lastName != null) iPerson = iPerson.Where(f => f.LastName == lastName)
          return iPerson.AsEnumerable().ToList();





          share|improve this answer























          • The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
            – Nick Chapsas
            Nov 12 at 9:23












          • @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
            – SNO
            Nov 12 at 14:49










          • Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
            – Nick Chapsas
            Nov 12 at 15:24










          • one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
            – SNO
            Nov 13 at 6:07















          up vote
          -1
          down vote










          up vote
          -1
          down vote









          Maybe you can work with IQueryable:



          IQueryable<Person> iPerson = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions);

          if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);
          if(lastName != null) iPerson = iPerson.Where(f => f.LastName == lastName)
          return iPerson.AsEnumerable().ToList();





          share|improve this answer














          Maybe you can work with IQueryable:



          IQueryable<Person> iPerson = this._client.CreateDocumentQuery<Person>(
          UriFactory.CreateDocumentCollectionUri(_idDatabase, _idCollection), queryOptions);

          if(Name != null) iPerson = iPerson.Where(f => f.Name == Name);
          if(lastName != null) iPerson = iPerson.Where(f => f.LastName == lastName)
          return iPerson.AsEnumerable().ToList();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 14:56

























          answered Nov 12 at 9:21









          SNO

          10910




          10910












          • The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
            – Nick Chapsas
            Nov 12 at 9:23












          • @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
            – SNO
            Nov 12 at 14:49










          • Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
            – Nick Chapsas
            Nov 12 at 15:24










          • one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
            – SNO
            Nov 13 at 6:07




















          • The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
            – Nick Chapsas
            Nov 12 at 9:23












          • @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
            – SNO
            Nov 12 at 14:49










          • Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
            – Nick Chapsas
            Nov 12 at 15:24










          • one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
            – SNO
            Nov 13 at 6:07


















          The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
          – Nick Chapsas
          Nov 12 at 9:23






          The CosmosDB SDK doesn't play nicely with the Equals method. It throws a NotSupported exception when it does the LINQ to SQL conversion. On top of that, youe queryable will actutually return nothing because a simple ToList() won't work. The SDK needs an Enumerable before it can return data with the ToList method. It's weird. Also also, he said that he wants the filter to work when one of the two is null not potentially both.
          – Nick Chapsas
          Nov 12 at 9:23














          @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
          – SNO
          Nov 12 at 14:49




          @nick Chapsas: Ok. To be hornest I haven't worked with CosmosDB SDK, just wanted to give an idea. Sorry for that confusion ;)
          – SNO
          Nov 12 at 14:49












          Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
          – Nick Chapsas
          Nov 12 at 15:24




          Still not quite what he asked for though. "I want to filter for two parameters and one of the two can be null".
          – Nick Chapsas
          Nov 12 at 15:24












          one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
          – SNO
          Nov 13 at 6:07






          one of the two CAN be null. And what is when both are null or both are set? And again, this should give CMorillo an idea how he can use IQueryable to write clean solutions.
          – SNO
          Nov 13 at 6:07




















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53259013%2fquery-with-lambda-expressions-and-one-parameter-is-null%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python