2 Replies - 1203 Views - Last Post: 17 June 2012 - 02:37 AM Rate Topic: -----

#1 insanepenguin  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 234
  • Joined: 08-July 10

Linq to Entities query

Posted 16 June 2012 - 12:23 PM

Hi guys,

I'm loading a query in a Silverlight application and have figured out how to return only today's records:

            var latestData = from w in this._weatherDataContext.GetWeatherDatasQuery()
                             where w.date.Day == DateTime.Today.Day
                             select w;
                          
                             
            
            try
            {
                loadOp = this._weatherDataContext.Load(latestData);

            }

            catch (Exception Ex)
            {
                //textBlock1.Text = Ex.Message;
            }
          
           loadOp.Completed += new EventHandler(loadOp_Completed);
         
           
        }

        void loadOp_Completed(object sender, EventArgs e)
        {
          this.DataContext = loadOp.Entities;
   
        }


Any ideas how I could edit the where clause to return records from today but in the last ten minutes only? Obviously at the moment I receive every record with today's date (the database adds a new record every minute)

Many thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Linq to Entities query

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,053
  • Joined: 17-July 10

Re: Linq to Entities query

Posted 17 June 2012 - 02:16 AM

you can use Substract method of the DateTime structure. The result will be a an object of type TimeSpan which has a property called Minutes.
Was This Post Helpful? 0
  • +
  • -

#3 insanepenguin  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 234
  • Joined: 08-July 10

Re: Linq to Entities query

Posted 17 June 2012 - 02:37 AM

Thank you, I will try that
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1