none
Returning multiple data from 2 tables RRS feed

  • Question

  • Hi all. I am very new to LinQ so help me out here.

    1) I have 2 tables Food and UserMeal. Both tables have a same field named FoodID. I want to return a decimal type from the UserMeal and a String type from Food. How do I return these 2 values through a web service? I am returning them to a Silverlight application.

    2) If I return the 2 values by selecting a date in the Calendar control in ASP.NET, how do I go about doing it?

    I am doing it in C#.
    Wednesday, August 12, 2009 2:37 PM

Answers

  • If you are passing this to Silverlight, I would never recommend passing a dataset through WCF to consume on the client side. I would recommend instead to create a Lookup class as follows:

    [DataContract]
    class Lookup
    {
      [DataMember]
      public int Amount {get; set; }
      [DataMember]
      public string Description {get; set; }
    }

    Then you would return this in your service by projecting into this type in your LINQ query:

    query = from f in dc.Foods
                join m in dc.UserMeals on f.FoodID Equals m.FoodID
                select new Lookup { Amount = m.Amount, Description = f.Description };
    return query.ToList();

    For the second part of your question, it sounds like you need to interop between silverlight and ASP.Net to have your silverlight control rebind based on new values in the calendar control. You should be able to find samples online for Silverlight/ASP.Net integeration fairly easily.

    Jim Wooley
    www.ThinqLinq.com

    http://www.LinqInAction.net - "LINQ In Action", The book is now available. Don't wait for the movie
    • Marked as answer by burger87 Friday, August 21, 2009 1:07 AM
    Thursday, August 20, 2009 9:32 PM
    Moderator
  • Thanks for all the replies.

    @Jim, I actually did something similar to your method, which is using a lookup class, although I didn't use LinQ, but SqlDataReader instead in the WCF Service.

    For the Calendar control, I did it by using the HtmlPage.Document.GetElementById(calendar) method, and it worked well.

    Thanks for the reply. It was very informative.

    • Marked as answer by burger87 Friday, August 21, 2009 1:08 AM
    Friday, August 21, 2009 1:07 AM

All replies

  • Hi burger87,

    If you want to query in the web service, I recommand that you fill the dataset in the client side and then pass the dataset to the web serviece.
    In the webservice, you can use LINQ to dataset to get the result you want.

    For your first requirement, it can easily be done after you refering to this document:
    http://msdn.microsoft.com/en-us/vbasic/bb688086.aspx
    It provides various of operators that you can use in LINQ to dataset.

    For your second question, it would be better if you post it in ASP.NET forum since this forum is mainly for winform applications. The two values are returned by the web service. How can it also be returned by the Calendar control? There is event of Calendar control that can deal with the change of selected date. It's not hard to find the solution by your own.

    Best Regards

    Yichun Feng

     

    Tuesday, August 18, 2009 10:39 AM
  • If you are passing this to Silverlight, I would never recommend passing a dataset through WCF to consume on the client side. I would recommend instead to create a Lookup class as follows:

    [DataContract]
    class Lookup
    {
      [DataMember]
      public int Amount {get; set; }
      [DataMember]
      public string Description {get; set; }
    }

    Then you would return this in your service by projecting into this type in your LINQ query:

    query = from f in dc.Foods
                join m in dc.UserMeals on f.FoodID Equals m.FoodID
                select new Lookup { Amount = m.Amount, Description = f.Description };
    return query.ToList();

    For the second part of your question, it sounds like you need to interop between silverlight and ASP.Net to have your silverlight control rebind based on new values in the calendar control. You should be able to find samples online for Silverlight/ASP.Net integeration fairly easily.

    Jim Wooley
    www.ThinqLinq.com

    http://www.LinqInAction.net - "LINQ In Action", The book is now available. Don't wait for the movie
    • Marked as answer by burger87 Friday, August 21, 2009 1:07 AM
    Thursday, August 20, 2009 9:32 PM
    Moderator
  • Thanks for all the replies.

    @Jim, I actually did something similar to your method, which is using a lookup class, although I didn't use LinQ, but SqlDataReader instead in the WCF Service.

    For the Calendar control, I did it by using the HtmlPage.Document.GetElementById(calendar) method, and it worked well.

    Thanks for the reply. It was very informative.

    • Marked as answer by burger87 Friday, August 21, 2009 1:08 AM
    Friday, August 21, 2009 1:07 AM