Multiple searching in Asp.net (entity framework) with multiple search boxes
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
add a comment |
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
add a comment |
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
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
asp.net-mvc
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
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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);
}
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
}
add a comment |
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);
}
add a comment |
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);
}
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);
}
answered Nov 23 '18 at 20:13
Sailesh Babu DoppalapudiSailesh Babu Doppalapudi
1,1151819
1,1151819
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited Nov 23 '18 at 20:22
answered Nov 23 '18 at 20:11
ShyjuShyju
144k87330435
144k87330435
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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