1 Replies - 1542 Views - Last Post: 12 February 2013 - 02:15 AM Rate Topic: -----

#1 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Greater and Less Than.

Posted 12 February 2013 - 01:40 AM

So part of my assignment, i've been told to 'show the first and last name of each employee who is paid more than X but less than Y'

The closest I've gotten in LINQ/SQL is

var emps = 
from e in Employees
let pop = from x in Employees where x.FirstName == "Luis" && x.LastName == "Popp" select x.Salary
let hun = from x in Employees where x.FirstName == "Alexander" && x.LastName == "Hunold" select x.Salary
where e.Salary > pop && e.Salary < hun
select e;




Unfortunately that gives an issue with.

Operator '>' cannot be applied to operands of type 'decimal?' and 'System.Linq.IQueryable<decimal?>'

Operator '<' cannot be applied to operands of type 'decimal?' and 'System.Linq.IQueryable<decimal?>'



In retrospect I should've put this in the .NET forum.

This post has been edited by Ghlavac: 12 February 2013 - 01:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Greater and Less Than.

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Greater and Less Than.

Posted 12 February 2013 - 02:15 AM

Well, you seem to be comparing an IQueryable<decimal> with a normal decimal value

I think you can resolve it by adding a FirstOrDefault() to the end of your queries.
(let pop = from x in Employees where x.FirstName == "Luis" && x.LastName == "Popp" select x.Salary)FirstOrDefault();


Similarly for you hun as well...
Hopefully, that should work.

regards,
Raghav

This post has been edited by raghav.naganathan: 12 February 2013 - 02:16 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1