i have generated a Linq to Sql class which looks like this.

so i have 3 querys which gets my data.
private IQueryable<Gesellschaft> loadedGesellschaft;
private IQueryable<Anschrift> loadedGesellschaftAnschrift;
private IQueryable<Email> loadedGesellschaftEmail;
private lgDataContext completeGesellschaft;
private void Button_Click(object sender, RoutedEventArgs e)
{
completeGesellschaft = new lgDatacontext();
loadedGesellschaft = completeGesellschaft.Gesellschaft.Where(gid => gid.GID == 2);
loadedGesellschaftAnschrift = completeGesellschaft.Anschrift.Where(FK_GID => FK_GID.FK_GesellschaftId == loadedGesellschaft.First().GID);
loadedGesellschaftEmail = completeGesellschaft.Email.Where(FK_GID => FK_GID.FK_AnschriftId == loadedHauptanschrift.First().idAnschrift);
}
After this i want to put these 3 on my page. The Result is something like this there one Office(loadedGesellschaft) and that has maybe more than one Adress(loadedGesellschaftAnschrift) and has maybe more than one Email(loadedGesellschaftEmail)
so i have on my window some textboxes which contain the fields from loadedGesellschaft and Adresses and Emails are stored in comboboxes.
do i always have to bind the itemsource of one Control e.g.
<ComboBox Name="CBox_GDEmail" />
CBoxGDEmail.Itemsource = loadedGesellschaftEmail;
or is there an possibility to put all three objects together to the datacontext of the window ?
First, create three classes:
Gesellschaft,Anschrift, andEmail. These classes are view models; they expose any property whose value you want to see in the view. MakeGesellschaftexpose anAnschriftenproperty of typeIEnumerable<Anschrift>, andAnschriftexpose anEmailsproperty of typeIEnumerable<Email>. (I’m just sort of guessing at what the plural of Anschrift is; pretty much all of my knowledge of German comes from board games.)In your XAML, create three
DataTemplates, e.g.:Obviously you’ll want to use a saner layout than sticking a bunch of controls in a
WrapPanel; this is just a proof of concept. TheDataTemplateforAnschriftshould similarly have aListBoxwhoseItemsSourceis bound toEmails.Once you’ve done this, all you need in your XAML is to set the
DataContextof aContentPresenterto an instance ofGesellschaft. It will be rendered using theDataTemplatethat you’ve defined for that type. ItsListBoxwill contain an item for eachAnschrift, rendered using that type’s template. U.s.w.Congratulations, you’re now using the MVVM pattern just like all the cool kids. There’s a lot more to learn about than just this, but this is a good start.