Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9
This is the forum to discuss the Wrox book Professional ASP.NET MVC 1.0 by Rob Conery, Scott Hanselman, Phil Haack, Scott Guthrie; ISBN: 978-0-470-38461-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 1.0 ISBN: 978-0-470-38461-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 13th, 2011, 07:16 AM
Authorized User
Points: 95, Level: 1
Points: 95, Level: 1 Points: 95, Level: 1 Points: 95, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 24
Thanks: 3
Thanked 0 Times in 0 Posts
Default public IQueryable Find method()

I am trying to enhance the Iqueryable Find method, very similar to:
public IQueryable<Dinner> FindUpcomingDinners()
{
return from dinner in db.Dinners
where dinner.EventDate > DateTime.Now
orderby dinner.EventDate
select dinner;
}
in NerdDinner.

In my GymAttendance, AttnRepository.cs (very similar to DinnerRepository.cs in NerdDinner), I am trying to query the database table on a selected date and the Time from/To, which I have as a float datatype.
Code:
        public IQueryable<Attendance> FindAttendance(DateTime SelDate, float SelTimeFrom, float SelTimeTo)
        {
            return from attendance in db.Attendances
                   where attendance.GA_Date == SelDate && SelTimeFrom >= attendance.GA_Time_From && SelTimeTo <= attendance.GA_Time_To
                   orderby attendance.GA_Date, attendance.GA_Time_From
                   select attendance;
        }
it gives me error:
Quote:
'>=' cannot be applied to operands of type 'float' and 'string'
on both
Quote:
SelTimeFrom >= attendance.GA_Time_From
and
Quote:
SelTimeTo <= attendance.GA_Time_To
Is this the right way to query multiple fields in a table? What could I do to query the time, which I store as float datatype?

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old July 13th, 2011, 07:24 AM
Imar's Avatar
Wrox Author
Points: 67,286, Level: 100
Points: 67,286, Level: 100 Points: 67,286, Level: 100 Points: 67,286, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,228
Thanks: 66
Thanked 1,416 Times in 1,396 Posts
Default

Quote:
Is this the right way to query multiple fields in a table? What could I do to query the time, which I store as float datatype?
Yes, but it seems that you're not storing them as floats, but as strings. Since the SelTimeFrom and SelTimeTo parameters are typed as floats, my guess is that attendance.GA_Time_From is actually a string, not a float.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
bh81 (July 13th, 2011)
  #3 (permalink)  
Old July 13th, 2011, 07:47 AM
Authorized User
Points: 95, Level: 1
Points: 95, Level: 1 Points: 95, Level: 1 Points: 95, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2011
Posts: 24
Thanks: 3
Thanked 0 Times in 0 Posts
Thumbs up

Thank you Imar again. I was just about to post my findings but you beat me to it. Yes, you are absolutely right, the
public float GA_Time_From { get; set; }
public float GA_Time_To { get; set; }
was indeed string before.

Many thanks again Imar. You're so efficient.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
When to use delegates or how to add a generic find method. gbianchi C# 2005 4 March 16th, 2009 08:05 AM
Using Find Method of ADO martinaccess Access 3 November 21st, 2007 06:35 AM
find method in Hibernate sikharsaikia Java Databases 3 August 10th, 2005 05:09 AM
Rows.Find () Method + Windows 98?? thomaz C# 1 March 15th, 2005 05:55 AM
Excel Automation Find Method jman Excel VBA 1 September 17th, 2003 06:10 AM



All times are GMT -4. The time now is 01:34 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.