Skip to main content

Microsoft Silverlight

Answered Question Displaying Multiple data sets held in single data setRSS Feed

(0)

Nic Oughton
Nic Oughton

Member

Member

9 points

13 Posts

Displaying Multiple data sets held in single data set

I have a problem which is driving me nuts. It may not be strictly a RIA problem but it is within a Silverlight 3/RIA environment that I am trying to implement.

The basic problem is this, one on my tables holds data for three different flavours of the same data.

So for example my table might be called tblMeal within that detail of meals can be breakfast, lunch and dinner

In my Silverlight dataform I want to display, for a person who has an entry in tblMeal for each breakfast, lunch and dinner, in a listbox for each meal type the meals eaten.

If I just Load the data using the defaults I get all meals listed in each listbox. If I add a filter function then the entityset is only populaer of data setsted for which ever meal type I call last.

I have considered creating additional entities for each meal type but have had not much success.

Should I create Domain Data Sources for each flavour of the same data?

Should I try filtering the data in the ListBox, but then this requires the UI to have knowledge of the data.

I am just looking for some ideas on the best approach to this problem.
My example is relatively generic as I have a number of datasets constructed in this way. If I am not able to get anywhere with this construct then it may be back to the drawing board on the database design!

Any help most gratefully received.

Thanks

Nic

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Re: Displaying Multiple data sets held in single data set

Do you need paging? If you need paging then you will need multiple DomainDataSources, one for each listbox. If you don't need paging then another option would be to get rid of the DomainDataSource completely and switch to using a ViewModel instead. Changing your database design is that last thing you should try.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

Nic Oughton
Nic Oughton

Member

Member

9 points

13 Posts

Re: Displaying Multiple data sets held in single data set

ColinBlair:
Changing your database design is that last thing you should t
- exactly right, thats just what I am trying to avoid

 

To be more specific lets say I have a table tblMeal it contains columns

id - auto number
mealType - int
mealTime - DateTime
calories - int

the meal type column relates to breakfast, lunch, dinner etc so 0 might = breakfast, 1 = lunch etc.

I have another table - lets say tblPeoplesMeals it would then hold a reference to a person and their meals so one person in one day may end up with three entries in the tblMeal table

Now to display the data, in a datform I want to be able to display seperately breakfasts, lunches and dinners
I want to start with the person, display a couple of fields about them and then using the power of EF display the meal data but seperately.
I can automatically display all of the data because my Load function calls the data for the person I am currently looking at.

The problem I am trying to solve is how to seperately display the data - so for example in seperate list boxes.

Any suggestions on how I could do that?

 Thanks

Nic

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Re: Displaying Multiple data sets held in single data set

Well, you could use a DataGrid. Something like:

<data:DataGrid ItemsSource="{Binding tblPeoplesMeals}" AutoGenerateColumns="False">
                <data:DataGrid.Columns>
                <data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DataForm>
                            </DataForm>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
</data:Datagrid>

I was originally thinking of just a plain ItemsControl but it would be hard to control the ordering of the meals without the DataGrid's internal sorting system.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

Nic Oughton
Nic Oughton

Member

Member

9 points

13 Posts

Re: Displaying Multiple data sets held in single data set

Apologies if I am being dense (it wouldn't be the first timeSmile) but how would that allow me to show the data seperately.

At the moment I am displaying the data in a templated listbox. It shows all of the data and I could order it as necessary, but what I would like to do is display it in say three controls. One each for breakfast, lunch and dinner. So breakfast would be in one list box or grid, lunch in another and dinner in another still. Is there someway of applyin a filet to each one without it effecting the overall content of the entity set?

[Thanks for your help on this BTW!]

 

Nic

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Answered Question

Re: Displaying Multiple data sets held in single data set

(July 7 - Historical note: this thread split after this solution was created. A better solution is in that second thread.)

 

Well, I am having trouble figuring out what the difference is between "seperate controls" and your templated listbox. The only difference to me is that seperate controls are hard coded and the listbox isn't, they both display seperate controls for each meal, you just have to specifiy what that control looks like.

Anyway, here is what I usually end up doing for something like this. I would add client side properties through a partial class onto the Person object. In this case you want Person.Breakfast, Person.Lunch, and Person.Dinner. Through a partial class on the Person object, just add in properties that do LINQ statements against the PersonMeals and then return the meal. It would look something like this:

 

namespace The.Correct.Namespace
public partial class Person
{
    public Meal Breakfast
    {
        get
        {
            return (from pm in PersonMeals
                    where pm.Meal.MealTypeId = 1
                    select pm.Meal).SingleOrDefault();
        }
    }
    public Meal Lunch
    {
        get
        {
            return (from pm in PersonMeals
                    where pm.Meal.MealTypeId = 2
                    select pm.Meal).SingleOrDefault();
        }
    }
    public Meal Dinner
    {
        get
        {
            return (from pm in PersonMeals
                    where pm.Meal.MealTypeId = 3
                    select pm.Meal).SingleOrDefault();
        }
    }
}
 

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

Nic Oughton
Nic Oughton

Member

Member

9 points

13 Posts

Re: Displaying Multiple data sets held in single data set

By seperate controls I mean literally three different list boxes. One each for breakfast, lunch and dinner.

The EntitySet loads the data for all three. So each time I bind the different controls I get all three meals shown in each one.
So for example, in your earlier grid sample code I get the three meals listed in each instance of the grid control.

My XAML page starts with by binding to a single record held in an EntitySet. This then links through to multiple records by traversing the Foreign Keys in the database, hence my ability to easily display the three records. If I create new methods in the DomainService to filter per meal the EntitySet for meal data is then only populated with the data from the last LoadMealsByType call.
If I create seperate methods to fill datasets I don't seem to be able to then get them to synch with the initial record being bound too (if I can get them to display at all)

 I feel like there is some missing key which will make all this very clear - but right now I am stumped!

I will work up a small demo tomorrow to link here to see if that helps with asking my question.

Thanks for your help so far Colin, my appreciated.

 Nic

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Re: Displaying Multiple data sets held in single data set

The partial class properties from my previous post should do what you want, they have nothing to do with the previous DataGrid solution.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

Nic Oughton
Nic Oughton

Member

Member

9 points

13 Posts

Re: Displaying Multiple data sets held in single data set

Ok, so having failed again to find a solution to my issue I have created a small sample based on what has been discussed earlier in this thread.
If you open up the solution and run it you should see a screen with a name at the top and then three list boxes (the screen aint pretty but thats not the point!)

Each list box contains three entries for each user, what I need to achieve (based on the data currently in the database) is one record per list box per user.
If I then add, say, another breakfast for user 1 that would be two entries in the breakfast list and one each in lunch and dinner etc.

Hopefully when you see it it will make sense. If anyone has any suggestions on how I can achieve what I am trying to do here please post.

Apologies again if I am just being dense and missing something real obvious!

The zip of my sample solution can be found here

Nic

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities