I need to filter, so I retrieve one model from a list where a field is equalto or greater than, but not more than, but I carn't figure out the not more than
.Where(v => v.Field >= 35).Where(v => v. not greater than 35)?
Well, if the value is greater than or equal to 35, then it's 35 or higher, right? And then on top of that you want to restrict it to not more than 35? I feel like one of us is missing something. Do you have a specific example? Or do you just mean equals?
Your logic of the codes is hard for me to understand……your first where will gain number smaller or equal to 35,but your 2nd will filter all the numbers larger than 34……;So if your numbers are integer,I don't think you can find a number which is smaller or
equal to 35,but larger than 34?
Your logic of the codes is hard for me to understand……your first where will gain number smaller or equal to 35,but your 2nd will filter all the numbers larger than 34……;So if your numbers are integer,I don't think you can find a number which is smaller or
equal to 35,but larger than 34?
EnenDaveyBoy
Participant
1465 Points
1145 Posts
IS there a not greater than lambda statement?
Jun 13, 2012 08:29 PM|LINK
I need to filter, so I retrieve one model from a list where a field is equalto or greater than, but not more than, but I carn't figure out the not more than
.Where(v => v.Field >= 35).Where(v => v. not greater than 35)?
Any suggestions would be appriciated
DarrellNorto...
All-Star
86555 Points
9624 Posts
Moderator
MVP
Re: IS there a not greater than lambda statement?
Jun 13, 2012 08:33 PM|LINK
What about:
.Where(x => x.Field >= 35 && x.Field <= 70);
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: IS there a not greater than lambda statement?
Jun 13, 2012 08:34 PM|LINK
Well, if the value is greater than or equal to 35, then it's 35 or higher, right? And then on top of that you want to restrict it to not more than 35? I feel like one of us is missing something. Do you have a specific example? Or do you just mean equals?
.Where(v => v.Field == 35)?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
EnenDaveyBoy
Participant
1465 Points
1145 Posts
Re: IS there a not greater than lambda statement?
Jun 13, 2012 09:31 PM|LINK
lets say I have a table called numbers which has an ID field and a numbers field
id number
1 10
2 20
3 30
4 40
5 50
and so on
all I have is 1 number 35, and I only want to return 1 record, the record which is closest but not over 35
BrockAllen
All-Star
27434 Points
4891 Posts
MVP
Re: IS there a not greater than lambda statement?
Jun 13, 2012 09:42 PM|LINK
Oh yea, I had something like this recently... so do the where and also an orderby and then take the first result:
.Where(x => x.Number <= 35).OrderByDescending(x=>x.Number).First()
I think this logic is right -- actually it's prolly not right but I think you get the idea :)
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
EnenDaveyBoy
Participant
1465 Points
1145 Posts
Re: IS there a not greater than lambda statement?
Jun 13, 2012 09:50 PM|LINK
Hi
I did think of that, but that seems like a lot of work and wondered it it was more efficitent to do
.Where(x => x.Number <= 35).Where(x => x.Number > 35 - 1).FirstOrDefault()
or another way to do it
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: IS there a not greater than lambda statement?
Jun 15, 2012 01:32 AM|LINK
Hey:)
I think
BrockAllen
is right……He has given you a full solution;
Your logic of the codes is hard for me to understand……your first where will gain number smaller or equal to 35,but your 2nd will filter all the numbers larger than 34……;So if your numbers are integer,I don't think you can find a number which is smaller or equal to 35,but larger than 34?
Kindly correct me if I take you wrong……
Reguards!
EnenDaveyBoy
Participant
1465 Points
1145 Posts
Re: IS there a not greater than lambda statement?
Jun 15, 2012 01:44 AM|LINK
.Where(x => x.Field >= 35 && x.Field < 35+1);
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: IS there a not greater than lambda statement?
Jun 15, 2012 01:49 AM|LINK
OK:-)
You see,suppose you have a list of numbers:10,15,20,15,30,35,40,45
And your first where:35,40,45
But your 2nd where:35
But
BrockAllen
is also right!
:D
EnenDaveyBoy
Participant
1465 Points
1145 Posts
Re: IS there a not greater than lambda statement?
Jun 15, 2012 02:18 AM|LINK
Thanks for the help