Click here to Skip to main content
15,070,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have select in linq and in where condition i am checking two times remarks. Is there way to optimize instead of having andalso condition.

dim List = (From c In db.DevData
                     Where c.remark <> "Cancelled" AndAlso c.remark <> "Completed"
                     Order By c.Id


What I have tried:

dim List = (From c In db.DevData
                     Where c.remark <> "Cancelled" AndAlso c.remark <> "Completed"
                     Order By c.Id
Posted
Updated 7-Apr-20 3:32am
Comments
Maciej Los 7-Apr-20 8:23am
   
What you mean by "optimize", in what context?

Note, taht we don't see you screen and can't read in your mind. Can you be more specific?
Chinnu2020 7-Apr-20 8:41am
   
Instead of writing c.remark two times can it be done in single way?
Maciej Los 7-Apr-20 9:20am
   
If you would like to be sure that system will inform me about your replies, please use "Reply" widget. You'll find it near to the nick (login) - on the right side.

As i mentioned, you need to be more specific. I have no idea how your database is designed, how many remarks is in there, and why do you use <> operator instead of = (equal).
Chinnu2020 24-Apr-20 13:43pm
   
dim List = (From c In db.DevData
Where c.remark <> "Cancelled" AndAlso c.remark <> "Completed"
Order By c.Id

when remark is null in database those records are not fetching. is there issue with above query?
Maciej Los 24-Apr-20 14:00pm
   
dim List = (From c In db.DevData
Where c.remark IsNot Nothing AndAlso c.remark <> "Cancelled" AndAlso c.remark <> "Completed"
Order By c.Id
Chinnu2020 24-Apr-20 14:31pm
   
even though remarks which is null is not display

Put your statuses ("Completed", "Cancelled" etc) in their own table with their own IDs and store the ID in your DevData column instead, so if Completed is 1 have a StatusID with a value of 1 in DevData. Now you can do your wheres using numbers rather than text, or you can join DevData with the Status table and say where Status.Name <> "Completed" etc and that should perform much better.
   
Please, read my comments to your question first.

You can use Where + Any[^], but i doubt it would improve, or even optimize, the performance of your query.

VB.NET
Dim remarks = {"Cancelled", "Completed"}
Dim list = from c in db.DevData.Where(Function(x) remarks.Any(Function(y) x.remark<>y))
           Order By c.Id
           Select ...
   
Comments
Chinnu2020 8-Apr-20 6:58am
   
i tried with above code its is giving as lamda expression cannot be converted to Boolean because Boolean is not delegate type

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900