Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7896457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:53:58+00:00 2026-06-03T07:53:58+00:00

i have read many posts but can not find my answer.my question is a

  • 0

i have read many posts but can not find my answer.my question is a little specific.in my silverlight project i want to get weather data like temp,status and date from yahoo weather and save it to my database countiniously by changing from its rss.so iused webclient and its DownloadStringAsync and DownloadStringCompleted for getting data.also i created a presentation model in my server in models folder(beacause i wanted to use it in my service) so in my DownloadStringCompleted event handler i have done something like this:

  void xmlclient_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e)
    {
        XNamespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0";
        if (e.Error == null)
        {
            XElement x = XElement.Parse(e.Result);
            weatherquery1 =
               from items in x.Descendants("item")

               select new BusinessApplication1.Web.Models.WeatherConditionModel
               {

               PubDate = items.Element(yweather +"condition").Attribute("date").Value,
               Status = items.Element(yweather + "condition").Attribute("text").Value
               };
             }

           }

this is in my viewmodel and i tested it all works.i can get data and also can see the result in datagrid or listbox.
inow i want to save data in my database.i want it to be done automatically and not by a button or a command.i want it to read data always and save it to database in every 5 minutes for example.so i created my service and i create a custom insert which i can shape it myself:

 private void MapwcModel(WeatherConditionTable wctable, WeatherConditionModel wcPM)
     {
        wctable.Status = wcPM.Status;
        wctable.PubDate = wcPM.PubDate;
        wctable.WeatherConditionID = wcPM.WeatherConditionID;

     }

    [Insert]
    [Invoke]
    public void InsertWeatherConditionData(WeatherConditionModel WeatherConditionData)
    {
        WeatherConditionTable wc = WeatherConditionContext.WeatherConditionTables.CreateObject();
        MapwcModel(wc, WeatherConditionData);
        wc.Status = WeatherConditionData.Status;
        wc.PubDate = WeatherConditionData.PubDate;
        WeatherConditionContext.WeatherConditionTables.AddObject(wc);
        WeatherConditionContext.SaveChanges();


    }

and my get data:

        public IQueryable<WeatherConditionModel> GetWeatherConditionData()
           {
         return from p in this.WeatherConditionContext.WeatherConditionTables
               select new WeatherConditionModel
               {
                   WeatherConditionID = p.WeatherConditionID,
                   Status = p.Status,
                   PubDate = p.PubDate,

               };
           }

now i do not know how to force it to save data.i wrote this in my iewmodel but did not work:

    foreach (BusinessApplication1.Web.Models.WeatherConditionModel el in weatherquery1)

                {
                WeatherConditionDomainContext context = new WeatherConditionDomainContext();
                EntityQuery<BusinessApplication1.Web.Models.WeatherConditionModel> weatherLoadQuery = context.GetWeatherConditionDataQuery();
                context.Load<BusinessApplication1.Web.Models.WeatherConditionModel>(weatherLoadQuery);
                context.SubmitChanges(delegate(SubmitOperation operation)
                {
                    if (operation.HasError)
                    {
                        operation.MarkErrorAsHandled();
                    }
                }, null);
                }

i do not know how to force insert method to work.someone please tell me in where i am wrong?i know there is somewhere.show me the way.
best regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:54:00+00:00Added an answer on June 3, 2026 at 7:54 am

    I found it .Many thanks to book: Silverlight 4 Unleased-
    chapter 13- from the great : Laurent Bugnion .

    first,there is no need to use the WeatherConditionModel as a presentation model
    (presentation model id used when you need to save data in multiple tables ).it is just a class used as
    holder of my query output.
    second,not need to change Insert method in the service at all(because here i want to save data in just one table)
    so , just create your service upon your entity model and build it.after build it in this way,
    you can call your table in your view model( which i could not,because i changed my service methods(i changed WeatherConditionTable
    to WeatherConditionModel(the class!!) manually as you saw).
    third,in my foreach loop,i can save my data to my database.
    .i have a combobox and a listbox and a button,i select my city
    from combobox,and hit button that uses a command to my GetRss and it does
    the job nicely now.it shows data and saves it to database.
    it is my view model code( described part):

          internal void GetRssFeed()
              {
                Feed selectedFeed = (Feed)FeedModel.FeedList[FeedModel.SelectedIndex];
                FeedModel.SelectedFeedName = selectedFeed.FeedName;
                WebClient xmlclient = new WebClient();
                xmlclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(xmlclient_DownloadStringCompleted);
            xmlclient.DownloadStringAsync(new Uri(selectedFeed.FeedUrl));
    
        }
    
        WeatherConditionDomainContext context = new WeatherConditionDomainContext();
        WeatherConditionTable wct = new WeatherConditionTable();
        void xmlclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            XNamespace yweather = "http://xml.weather.yahoo.com/ns/rss/1.0";
            if (e.Error == null)
            {
    
                XElement x = XElement.Parse(e.Result);
                weatherquery1 =
                   from items in x.Descendants("channel")
                   let item=items.Element("item")
                   select new WeatherConditionModel
                   {
                       Temp = Convert.ToInt32(item.Element(yweather + "condition").Attribute("temp").Value),
                       PubDate = item.Element(yweather + "condition").Attribute("date").Value,
                       Status = item.Element(yweather + "condition").Attribute("text").Value,
                       Humidity=Convert.ToInt32(items.Element(yweather + "atmosphere").Attribute("humidity").Value)
                   };
    
                foreach (WeatherConditionModel wc in weatherquery1)
               {
    
                       wct.Temp = wc.Temp;
                       wct.Status = wc.Status;
                       wct.PubDate = DateTime.Now.ToShortTimeString();
                       wct.Humidity = wc.Humidity;
                       context.WeatherConditionTables.Add(wct);
                       context.SubmitChanges();
    
    
               }
            }
            else
            {
                MessageBox.Show(e.Error.Message);
            }
        }
    

    thanks for all attention.i hope it helped someone.tell me if anyone have better ideas.
    please mark as answer if it helped anyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read many questions about the facebook login but until not I didnt
I have read in many places that WPF combo does not support autocomplete but
I have read other related posts, but am still not quite sure how, or
I have read many posts regarding detection of popup blocker by javascript code but
I've read so many posts and still can't find or understand how to handle
I have read many answers and blog posts on the jQuery queues... and specifically
I have read many questions about Android, J2ME and RecordStore , but I still
OK I have read many posts regarding Dual Licensing using MIT and GPL licenses.
I've already noticed that there are many posts dealing with this; but I can't
Alright...I've given the site a fair search and have read over many posts about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.