Multiple searching in Asp.net (entity framework) with multiple search boxes












0














ImageI'm having a problem to develop a form that can be search by multiple search boxes.....when i'm trying to search name and email together ActionResult...compiler says both linq queries cannot be applied with && operator..i don.t know why...





[HttpPost]
public ActionResult Login(string search,string search2)
{
var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search)) && db.Emps.Where(x=>x.Employee_email.StartsWith(search2));
return View(obj);
}












share|improve this question





























    0














    ImageI'm having a problem to develop a form that can be search by multiple search boxes.....when i'm trying to search name and email together ActionResult...compiler says both linq queries cannot be applied with && operator..i don.t know why...





    [HttpPost]
    public ActionResult Login(string search,string search2)
    {
    var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search)) && db.Emps.Where(x=>x.Employee_email.StartsWith(search2));
    return View(obj);
    }












    share|improve this question



























      0












      0








      0







      ImageI'm having a problem to develop a form that can be search by multiple search boxes.....when i'm trying to search name and email together ActionResult...compiler says both linq queries cannot be applied with && operator..i don.t know why...





      [HttpPost]
      public ActionResult Login(string search,string search2)
      {
      var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search)) && db.Emps.Where(x=>x.Employee_email.StartsWith(search2));
      return View(obj);
      }












      share|improve this question















      ImageI'm having a problem to develop a form that can be search by multiple search boxes.....when i'm trying to search name and email together ActionResult...compiler says both linq queries cannot be applied with && operator..i don.t know why...





      [HttpPost]
      public ActionResult Login(string search,string search2)
      {
      var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search)) && db.Emps.Where(x=>x.Employee_email.StartsWith(search2));
      return View(obj);
      }









      asp.net-mvc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 21:19









      Sailesh Babu Doppalapudi

      1,1151819




      1,1151819










      asked Nov 23 '18 at 20:07









      Alyan khanAlyan khan

      11




      11
























          2 Answers
          2






          active

          oldest

          votes


















          0














          You need to use both conditions inside single Where



          [HttpPost]
          public ActionResult Login(string search,string search2)
          {
          var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) && x.Employee_email.StartsWith(search2));
          return View(obj);
          }





          share|improve this answer





























            0














            If you look at your current code, the first part db.Emps.Where(x => x.Employee_name.StartsWith(search)) is going to return a collection, IQueryable<Emp>
            and the second part of the expression will also return the same type, IQueryable<Emp>.



            So your code is basically trying to execute/compile the expression IQueryable<Emp> && IQueryable<Emp> and since it is not valid, the compiler is telling you that it is not valid.



            Ideally, you should have both of your WHERE condition predicates inside the same Where method.



            var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
            && x.Employee_email.StartsWith(search2));


            Keep in mind that, the variable obj is still of type IQueryable<Emp>. If you want to execute your LINQ query, you may call the ToList() method.



            List<Emp> = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
            && x.Employee_email.StartsWith(search2)).ToList();


            If you make the above change, make sure your view is strongly typed to List<Emp> instead of IQueryable






            share|improve this answer























              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%2f53452417%2fmultiple-searching-in-asp-net-entity-framework-with-multiple-search-boxes%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You need to use both conditions inside single Where



              [HttpPost]
              public ActionResult Login(string search,string search2)
              {
              var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) && x.Employee_email.StartsWith(search2));
              return View(obj);
              }





              share|improve this answer


























                0














                You need to use both conditions inside single Where



                [HttpPost]
                public ActionResult Login(string search,string search2)
                {
                var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) && x.Employee_email.StartsWith(search2));
                return View(obj);
                }





                share|improve this answer
























                  0












                  0








                  0






                  You need to use both conditions inside single Where



                  [HttpPost]
                  public ActionResult Login(string search,string search2)
                  {
                  var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) && x.Employee_email.StartsWith(search2));
                  return View(obj);
                  }





                  share|improve this answer












                  You need to use both conditions inside single Where



                  [HttpPost]
                  public ActionResult Login(string search,string search2)
                  {
                  var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) && x.Employee_email.StartsWith(search2));
                  return View(obj);
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 20:13









                  Sailesh Babu DoppalapudiSailesh Babu Doppalapudi

                  1,1151819




                  1,1151819

























                      0














                      If you look at your current code, the first part db.Emps.Where(x => x.Employee_name.StartsWith(search)) is going to return a collection, IQueryable<Emp>
                      and the second part of the expression will also return the same type, IQueryable<Emp>.



                      So your code is basically trying to execute/compile the expression IQueryable<Emp> && IQueryable<Emp> and since it is not valid, the compiler is telling you that it is not valid.



                      Ideally, you should have both of your WHERE condition predicates inside the same Where method.



                      var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                      && x.Employee_email.StartsWith(search2));


                      Keep in mind that, the variable obj is still of type IQueryable<Emp>. If you want to execute your LINQ query, you may call the ToList() method.



                      List<Emp> = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                      && x.Employee_email.StartsWith(search2)).ToList();


                      If you make the above change, make sure your view is strongly typed to List<Emp> instead of IQueryable






                      share|improve this answer




























                        0














                        If you look at your current code, the first part db.Emps.Where(x => x.Employee_name.StartsWith(search)) is going to return a collection, IQueryable<Emp>
                        and the second part of the expression will also return the same type, IQueryable<Emp>.



                        So your code is basically trying to execute/compile the expression IQueryable<Emp> && IQueryable<Emp> and since it is not valid, the compiler is telling you that it is not valid.



                        Ideally, you should have both of your WHERE condition predicates inside the same Where method.



                        var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                        && x.Employee_email.StartsWith(search2));


                        Keep in mind that, the variable obj is still of type IQueryable<Emp>. If you want to execute your LINQ query, you may call the ToList() method.



                        List<Emp> = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                        && x.Employee_email.StartsWith(search2)).ToList();


                        If you make the above change, make sure your view is strongly typed to List<Emp> instead of IQueryable






                        share|improve this answer


























                          0












                          0








                          0






                          If you look at your current code, the first part db.Emps.Where(x => x.Employee_name.StartsWith(search)) is going to return a collection, IQueryable<Emp>
                          and the second part of the expression will also return the same type, IQueryable<Emp>.



                          So your code is basically trying to execute/compile the expression IQueryable<Emp> && IQueryable<Emp> and since it is not valid, the compiler is telling you that it is not valid.



                          Ideally, you should have both of your WHERE condition predicates inside the same Where method.



                          var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                          && x.Employee_email.StartsWith(search2));


                          Keep in mind that, the variable obj is still of type IQueryable<Emp>. If you want to execute your LINQ query, you may call the ToList() method.



                          List<Emp> = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                          && x.Employee_email.StartsWith(search2)).ToList();


                          If you make the above change, make sure your view is strongly typed to List<Emp> instead of IQueryable






                          share|improve this answer














                          If you look at your current code, the first part db.Emps.Where(x => x.Employee_name.StartsWith(search)) is going to return a collection, IQueryable<Emp>
                          and the second part of the expression will also return the same type, IQueryable<Emp>.



                          So your code is basically trying to execute/compile the expression IQueryable<Emp> && IQueryable<Emp> and since it is not valid, the compiler is telling you that it is not valid.



                          Ideally, you should have both of your WHERE condition predicates inside the same Where method.



                          var obj = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                          && x.Employee_email.StartsWith(search2));


                          Keep in mind that, the variable obj is still of type IQueryable<Emp>. If you want to execute your LINQ query, you may call the ToList() method.



                          List<Emp> = db.Emps.Where(x => x.Employee_name.StartsWith(search) 
                          && x.Employee_email.StartsWith(search2)).ToList();


                          If you make the above change, make sure your view is strongly typed to List<Emp> instead of IQueryable







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 23 '18 at 20:22

























                          answered Nov 23 '18 at 20:11









                          ShyjuShyju

                          144k87330435




                          144k87330435






























                              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%2f53452417%2fmultiple-searching-in-asp-net-entity-framework-with-multiple-search-boxes%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

                              A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                              Calculate evaluation metrics using cross_val_predict sklearn

                              Insert data from modal to MySQL (multiple modal on website)